]> git.kianting.info Git - clo/blob - src/libclo/index.js
add cjk splitter
[clo] / src / libclo / index.js
1 "use strict";
2 Object.defineProperty(exports, "__esModule", { value: true });
3 exports.a = exports.Clo = void 0;
4 const canva_1 = require("../canva");
5 /**
6 * TYPES
7 */
8 /**
9 * text direction
10 * LTR - left to right
11 * TTB - top to bottom
12 * etc.
13 */
14 var Direction;
15 (function (Direction) {
16 Direction[Direction["LTR"] = 0] = "LTR";
17 Direction[Direction["RTL"] = 1] = "RTL";
18 Direction[Direction["TTB"] = 2] = "TTB";
19 Direction[Direction["BTT"] = 3] = "BTT";
20 })(Direction || (Direction = {}));
21 /**
22 * DEFAULT CONST PART
23 */
24 const A4_IN_PX = { "width": 793.7,
25 "height": 1122.5 };
26 const defaultTextStyle = {
27 family: "FreeSans",
28 size: 12,
29 textWeight: canva_1.TextWeight.REGULAR,
30 textStyle: canva_1.TextStyle.ITALIC,
31 };
32 const defaultFrameStyle = {
33 directionInsideLine: Direction.LTR,
34 direction: Direction.TTB,
35 baseLineskip: ptToPx(15),
36 fontStyle: defaultTextStyle,
37 x: A4_IN_PX.width * 0.10,
38 y: A4_IN_PX.height * 0.10,
39 width: A4_IN_PX.width * 0.80,
40 height: A4_IN_PX.height * 0.80,
41 content: null,
42 };
43 const cjkvBlocksInRegex = ["Hani"];
44 const cjkvRegexPattern = new RegExp("((?:" +
45 cjkvBlocksInRegex.map((x) => "\\p{Script_Extensions=" + x + "}").join("|") + ")+)", "gu");
46 /**
47 * FUNCTION PART
48 */
49 /**
50 * convert from ptToPx
51 * @param pt pt size value
52 * @returns the corresponding px value
53 */
54 function ptToPx(pt) {
55 return pt * 4 / 3.0;
56 }
57 /**
58 * REGISTER PART
59 */
60 /**
61 * split CJKV and non-CJKV
62 *
63 * @param arr : input tkTree
64 * @returns
65 */
66 function splitCJKV(arr) {
67 console.log(arr);
68 var result = [];
69 for (let i = 0; i < arr.length; i++) {
70 var item = arr[i];
71 if (!Array.isArray(item)) {
72 console.log(item.split(cjkvRegexPattern));
73 result = result.concat(item.split(cjkvRegexPattern));
74 }
75 else {
76 result.push(item);
77 }
78 }
79 console.log(result);
80 return result;
81 }
82 class Clo {
83 constructor() {
84 this.preprocessors = [];
85 this.mainStream = [];
86 this.attributes = { "page": A4_IN_PX };
87 // register the precessor functions
88 this.preprocessorRegister(splitCJKV);
89 }
90 setAttr(attr, val) {
91 Object.assign(this.attributes, attr, val);
92 }
93 getAttr(attr) {
94 if (Object.keys(this.attributes).length === 0) {
95 return this.attributes[attr];
96 }
97 else {
98 return undefined;
99 }
100 }
101 /**
102 * register a function of preprocessor
103 * @param f a function
104 */
105 preprocessorRegister(f) {
106 this.preprocessors.push(f);
107 }
108 generatePdf() {
109 // preprocessed
110 var prepro = this.mainStream;
111 for (var i = 0; i < this.preprocessors.length; i++) {
112 prepro = this.preprocessors[i](prepro);
113 }
114 // TODO
115 console.log("test" + prepro);
116 }
117 }
118 exports.Clo = Clo;
119 exports.a = new Clo();
120 exports.default = exports.a;