67 lines
2 KiB
Markdown
67 lines
2 KiB
Markdown
|
這个程式借Knuth ê排版理論,但是為著欲予列位知影所以mā是佇tsia介紹:
|
|||
|
|
|||
|
|
|||
|
|
|||
|
![a.svg](:/af607cb6cd2a4c34ab3c80f65efcee84)
|
|||
|
|
|||
|
### 2.2 一个盒仔ê結構
|
|||
|
#### 2.2.1 咱這馬來看一个盒仔ê (Box) 結構,ē當分做若以上ê圖講ê部件:
|
|||
|
|
|||
|
`Box is a subtype of Element`
|
|||
|
|
|||
|
|屬性英語名|型別|臺語解說|
|
|||
|
|-----|----|-----|
|
|||
|
| basePoint | Position| 定義安khǹg盒仔ê基點。 |
|
|||
|
| baseLineDirection | Rection | 定義基線(安khǹg元素ê基準線)ê方向|
|
|||
|
| width | float | 基線ê長度(pt)
|
|||
|
| height |float| BaseLine 射出去ê方向ê「倒pîng」ê長度 (pt)(m̄是kui个ê懸度 totalHeight)
|
|||
|
| depth | float | BaseLine 射出去ê方向ê「正pîng」ê長度 (pt)
|
|||
|
| elements | Element List | 所有內底收囥ê元素ê列單(list),照baseLineDirection ê 方向,沿 baseLine 排in ê基點
|
|||
|
| elementsBaseSkip | float | `elementsSpaging[i] == elements[i] 基點之間ê距離 (BaseSkip)` (px)
|
|||
|
| pageNo | PageNo | 所屬佇ê頁數 |
|
|||
|
|
|||
|
|
|||
|
其中
|
|||
|
```OCaml
|
|||
|
Position = struct {x: Float, y : Float}
|
|||
|
Direction = Up | Down | Left | Right
|
|||
|
```
|
|||
|
#### 2.2.2相關ê函數:
|
|||
|
|
|||
|
|英語名|型別|臺語解說|
|
|||
|
|-----|---|-------|
|
|||
|
|len_of_elements | box -> int | len_of_elements box = length (box.elements)
|
|||
|
| totalHeight | box -> float | `totalHeight box = box.height + box.depth`
|
|||
|
| insert_element | box -> element List -> Option | 插入一个`element List`內底ê逐个元素kàu一个Box,逐个baseSkip是固定ê float,轉來`Result Box` 猶是`Exception`(that滿ê時)。(例見下kha) |
|
|||
|
|
|||
|
|
|||
|
|
|||
|
```OCaml
|
|||
|
let a_box = Box{
|
|||
|
basePoint = (70.0,50.0),
|
|||
|
baseLineDirection = DOWN,
|
|||
|
width = 400.0,
|
|||
|
height = 700.0,
|
|||
|
depth = 0.0,
|
|||
|
elements = [],
|
|||
|
elementsBaseSkip = [],
|
|||
|
pageNo = 3
|
|||
|
};
|
|||
|
|
|||
|
let a_char_list = List.map [天, 地, 儂] fun x -> CharToBox x
|
|||
|
12.0 (*font-size*)
|
|||
|
"AR PL New Sung" (*font-family*)
|
|||
|
300 (*font weight*)
|
|||
|
Normal (*font style*);;
|
|||
|
|
|||
|
let new_a_box = insert_element a_box a_char_list
|
|||
|
new_a_box : Option Box
|
|||
|
```
|
|||
|
|
|||
|
|
|||
|
|
|||
|
其中
|
|||
|
```OCaml
|
|||
|
Option = Result a | Exception str
|
|||
|
```
|