Go to most recent revision | Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
4680 | right-hear | 1 | #include "fitz.h" |
2 | #include "mupdf.h" |
||
3 | |||
4 | void |
||
5 | pdf_set_font_wmode(pdf_font_desc *font, int wmode) |
||
6 | { |
||
7 | font->wmode = wmode; |
||
8 | } |
||
9 | |||
10 | void |
||
11 | pdf_set_default_hmtx(pdf_font_desc *font, int w) |
||
12 | { |
||
13 | font->dhmtx.w = w; |
||
14 | } |
||
15 | |||
16 | void |
||
17 | pdf_set_default_vmtx(pdf_font_desc *font, int y, int w) |
||
18 | { |
||
19 | font->dvmtx.y = y; |
||
20 | font->dvmtx.w = w; |
||
21 | } |
||
22 | |||
23 | void |
||
24 | pdf_add_hmtx(pdf_font_desc *font, int lo, int hi, int w) |
||
25 | { |
||
26 | if (font->hmtx_len + 1 >= font->hmtx_cap) |
||
27 | { |
||
28 | font->hmtx_cap = font->hmtx_cap + 16; |
||
29 | font->hmtx = fz_realloc(font->hmtx, font->hmtx_cap, sizeof(pdf_hmtx)); |
||
30 | } |
||
31 | |||
32 | font->hmtx[font->hmtx_len].lo = lo; |
||
33 | font->hmtx[font->hmtx_len].hi = hi; |
||
34 | font->hmtx[font->hmtx_len].w = w; |
||
35 | font->hmtx_len++; |
||
36 | } |
||
37 | |||
38 | void |
||
39 | pdf_add_vmtx(pdf_font_desc *font, int lo, int hi, int x, int y, int w) |
||
40 | { |
||
41 | if (font->vmtx_len + 1 >= font->vmtx_cap) |
||
42 | { |
||
43 | font->vmtx_cap = font->vmtx_cap + 16; |
||
44 | font->vmtx = fz_realloc(font->vmtx, font->vmtx_cap, sizeof(pdf_vmtx)); |
||
45 | } |
||
46 | |||
47 | font->vmtx[font->vmtx_len].lo = lo; |
||
48 | font->vmtx[font->vmtx_len].hi = hi; |
||
49 | font->vmtx[font->vmtx_len].x = x; |
||
50 | font->vmtx[font->vmtx_len].y = y; |
||
51 | font->vmtx[font->vmtx_len].w = w; |
||
52 | font->vmtx_len++; |
||
53 | } |
||
54 | |||
55 | static int cmph(const void *a0, const void *b0) |
||
56 | { |
||
57 | pdf_hmtx *a = (pdf_hmtx*)a0; |
||
58 | pdf_hmtx *b = (pdf_hmtx*)b0; |
||
59 | return a->lo - b->lo; |
||
60 | } |
||
61 | |||
62 | static int cmpv(const void *a0, const void *b0) |
||
63 | { |
||
64 | pdf_vmtx *a = (pdf_vmtx*)a0; |
||
65 | pdf_vmtx *b = (pdf_vmtx*)b0; |
||
66 | return a->lo - b->lo; |
||
67 | } |
||
68 | |||
69 | void |
||
70 | pdf_end_hmtx(pdf_font_desc *font) |
||
71 | { |
||
72 | if (!font->hmtx) |
||
73 | return; |
||
74 | qsort(font->hmtx, font->hmtx_len, sizeof(pdf_hmtx), cmph); |
||
75 | } |
||
76 | |||
77 | void |
||
78 | pdf_end_vmtx(pdf_font_desc *font) |
||
79 | { |
||
80 | if (!font->vmtx) |
||
81 | return; |
||
82 | qsort(font->vmtx, font->vmtx_len, sizeof(pdf_vmtx), cmpv); |
||
83 | } |
||
84 | |||
85 | pdf_hmtx |
||
86 | pdf_get_hmtx(pdf_font_desc *font, int cid) |
||
87 | { |
||
88 | int l = 0; |
||
89 | int r = font->hmtx_len - 1; |
||
90 | int m; |
||
91 | |||
92 | if (!font->hmtx) |
||
93 | goto notfound; |
||
94 | |||
95 | while (l <= r) |
||
96 | { |
||
97 | m = (l + r) >> 1; |
||
98 | if (cid < font->hmtx[m].lo) |
||
99 | r = m - 1; |
||
100 | else if (cid > font->hmtx[m].hi) |
||
101 | l = m + 1; |
||
102 | else |
||
103 | return font->hmtx[m]; |
||
104 | } |
||
105 | |||
106 | notfound: |
||
107 | return font->dhmtx; |
||
108 | } |
||
109 | |||
110 | pdf_vmtx |
||
111 | pdf_get_vmtx(pdf_font_desc *font, int cid) |
||
112 | { |
||
113 | pdf_hmtx h; |
||
114 | pdf_vmtx v; |
||
115 | int l = 0; |
||
116 | int r = font->vmtx_len - 1; |
||
117 | int m; |
||
118 | |||
119 | if (!font->vmtx) |
||
120 | goto notfound; |
||
121 | |||
122 | while (l <= r) |
||
123 | { |
||
124 | m = (l + r) >> 1; |
||
125 | if (cid < font->vmtx[m].lo) |
||
126 | r = m - 1; |
||
127 | else if (cid > font->vmtx[m].hi) |
||
128 | l = m + 1; |
||
129 | else |
||
130 | return font->vmtx[m]; |
||
131 | } |
||
132 | |||
133 | notfound: |
||
134 | h = pdf_get_hmtx(font, cid); |
||
135 | v = font->dvmtx; |
||
136 | v.x = h.w / 2; |
||
137 | return v; |
||
138 | }>=>>=> |