- 20231010: 初步完成tsit ê階段ê Parser`。
- 20231012: clo->js converter successfully (maybe.)
- 20231016:basic font guessing and `putText` function
- - 20231023-24:fix .ttc bug.
\ No newline at end of file
+ - 20231023-24:fix .ttc bug.
+
+ ## 之後的做法
+ - 先做一個前處理註冊器,註冊下列的前處理
+ - 中英文間距
+ - 換行點
+ - 空白轉為 [glue]
+ - 前處理完成字串後,必須要:
+ - 算出字元的Box
+ - 利用 frame/box 資訊分行、分頁
+ - 然後算出每個Box的x, y, page
+ - 最後納入排版
+
+## 排版語法:
+
+使用lisp表示,但其實是陣列
+```lisp
+ (hglue 寬度 伸展值)
+ (vglue 高度 伸展值)
+ (breakpoint 原始模式 斷行模式)
+ (em 數字)
+ (ex 數字)
+ (span {"font-family" : "Noto Sans" , "font-size" : 16 })
+ (vbox 高度 內容)
+```
\ No newline at end of file
--- /dev/null
+---
+many臺中daylight
+
+aaa collee
\ No newline at end of file
--- /dev/null
+
+/* clo, a typesetting engine, generated JS file*/
+/* CLO: beginning of head*/
+
+let cloLib = require("./src/libclo/index.js");
+let clo = new cloLib.Clo();
+
+/* CLO: end of head*/
+
+/* CLO: beginning of middle part*/
+clo.mainStream = /* CLO: end of middle part*/
+[`
+`, `many臺中daylight`, `
+
+`, `aaa`, ` `, `collee`];
+/* CLO: beginning of end part*/
+clo.generatePdf();
+/*CLO : end of end part*/
{
+ "type": "commonjs",
"name": "clo",
"version": "0.0.1",
"description": "a little typesetting engine in TypeScript",
--- /dev/null
+"use strict";
+Object.defineProperty(exports, "__esModule", { value: true });
+exports.a = exports.Clo = void 0;
+function foo(arr) {
+ for (let i = 0; i < arr.length; i++) {
+ }
+ if (Array.isArray(arr)) {
+ arr.push("balabala");
+ }
+ return arr;
+}
+class Clo {
+ constructor() {
+ this.preprocessors = [];
+ this.mainStream = [];
+ this.attributes = { "page": [793.7, 1122.5] };
+ this.preprocessorRegister(foo);
+ }
+ /**
+ * register a function of preprocessor
+ * @param f a function
+ */
+ preprocessorRegister(f) {
+ this.preprocessors.push(f);
+ }
+ generatePdf() {
+ // preprocessed
+ var prepro = this.mainStream;
+ for (var i = 0; i < this.preprocessors.length; i++) {
+ prepro = this.preprocessors[i](prepro);
+ }
+ // TODO
+ console.log("test" + prepro);
+ }
+}
+exports.Clo = Clo;
+exports.a = new Clo();
+exports.default = exports.a;
--- /dev/null
+import {tkTree} from "../parser";
+
+
+function foo(arr : tkTree): tkTree{
+ for (let i = 0; i < arr.length; i++) {
+
+ }
+ if (Array.isArray(arr)){
+ arr.push("balabala");
+ }
+ return arr;
+}
+
+export class Clo{
+ mainStream : Array<string>;
+ preprocessors : Array<Function>;
+ attributes: object ; // a4 size(x,y)
+
+
+ constructor(){
+ this.preprocessors = [];
+ this.mainStream = [];
+ this.attributes = {"page" : [793.7, 1122.5]};
+ this.preprocessorRegister(foo);
+ }
+
+ /**
+ * register a function of preprocessor
+ * @param f a function
+ */
+ public preprocessorRegister(f : Function){
+ this.preprocessors.push(f);
+ }
+
+ public generatePdf(){
+ // preprocessed
+ var prepro = this.mainStream;
+ for (var i = 0; i<this.preprocessors.length; i++){
+ prepro = this.preprocessors[i](prepro);
+ }
+ // TODO
+ console.log("test"+prepro);
+ }
+
+
+}
+
+export let a = new Clo();
+export default a;
\ No newline at end of file
return str;
}*/
-type tkTree = string | tkTree[];
+export type tkTree = string | tkTree[];
enum TokenKind {
Seperator, // ---
return ["%clo", first , second[1]];
}
+function applyPartsWithoutImport(parsed: [Token<TokenKind>, tkTree]):tkTree {
+return ["%clo", "" , parsed[1]];
+}
+
function applyComment(value: Token<TokenKind.Comment>): tkTree[]{
return [value.text];
);
/**
- * PROG : IMPORTS '---' CONTENT;
+ * PROG : IMPORTS '---' CONTENT | '---' CONTNENT
*/
PROG.setPattern(
- p.lrec_sc(IMPORTS, p.seq(p.str('---'), CONTENT), applyParts)
+ p.alt(
+ p.lrec_sc(IMPORTS, p.seq(p.str('---'), CONTENT), applyParts),
+ p.apply(p.seq(p.str('---'), CONTENT), applyPartsWithoutImport))
)
let outputHead = `
/* clo, a typesetting engine, generated JS file*/
/* CLO: beginning of head*/
-import * as clo from "clo";
-cl = clo.initClo();
+let cloLib = require("./src/libclo/index.js");
+let clo = new cloLib.Clo();
+
/* CLO: end of head*/\n`
/**
*/
let outputMiddle =`
/* CLO: beginning of middle part*/
-cl.mainText = /* CLO: end of middle part*/
+clo.mainStream = /* CLO: end of middle part*/
`
let outputEnd =`
/* CLO: beginning of end part*/
-cl.generatePdf();
+clo.generatePdf();
/*CLO : end of end part*/
`
* Convert `tree` (ASTTree; `tkTree`) to JS Code.
*/
export function treeToJS(tree : tkTree): string{
+
let head = tree[0];
if (head == "%clo"){
let totalResult = outputHead + treeToJS(tree[1]) +
let tail = tree[1];
if (Array.isArray(tail)){
if (tail.length == 1){
- return treeToJS(tail);
+ return tail.map((x)=>treeToJS(x)).join("').concat('")+ ";";
}
let tailStrings = tail.map((x)=>treeToJS(x));
return "(" + tailStrings.join(').concat(') + ");";
let decoratedArray = textContents
.flatMap(x=>String(x))
.map(x=>x.replace("\`","\\\`"));
-
+
return "[`" + decoratedArray.join("\`, \`") + "`]";
}else{
let decorated = textContents.replace("\`","\\\`");