-
Notifications
You must be signed in to change notification settings - Fork 112
Expand file tree
/
Copy pathsmart_font.hpp
More file actions
165 lines (145 loc) · 5.23 KB
/
Copy pathsmart_font.hpp
File metadata and controls
165 lines (145 loc) · 5.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
/******************************************************************************
* MODULE : smart_font.hpp
* DESCRIPTION: smart merging of several fonts for different unicode ranges
* COPYRIGHT : (C) 2013 Joris van der Hoeven
*******************************************************************************
* This software falls under the GNU general public license version 3 or later.
* It comes WITHOUT ANY WARRANTY WHATSOEVER. For details, see the file LICENSE
* in the root directory or <tp://www.gnu.org/licenses/gpl-3.0.html>.
******************************************************************************/
#ifndef SMART_FONT_HPP
#define SMART_FONT_HPP
#include "analyze.hpp"
#include "font.hpp"
#include "resource.hpp"
/******************************************************************************
* Efficient computation of the appropriate subfont
******************************************************************************/
RESOURCE (smart_map);
#define SUBFONT_MAIN 0
#define SUBFONT_ERROR 1
#define REWRITE_NONE 0
#define REWRITE_MATH 1
#define REWRITE_CYRILLIC 2
#define REWRITE_LETTERS 3
#define REWRITE_SPECIAL 4
#define REWRITE_EMULATE 5
#define REWRITE_POOR_BBB 6
#define REWRITE_ITALIC_GREEK 7
#define REWRITE_UPRIGHT_GREEK 8
#define REWRITE_UPRIGHT 9
#define REWRITE_ITALIC 10
#define REWRITE_IGNORE 11
struct smart_map_rep : rep<smart_map> {
int chv[256];
hashmap<string, int> cht;
hashmap<tree, int> fn_nr;
array<tree> fn_spec;
array<int> fn_rewr;
public:
smart_map_rep (string name, tree fn)
: rep<smart_map> (name), cht (-1), fn_nr (-1), fn_spec (2), fn_rewr (2) {
(void) fn;
for (int i= 0; i < 256; i++)
chv[i]= -1;
fn_nr (tuple ("main")) = SUBFONT_MAIN;
fn_nr (tuple ("error"))= SUBFONT_ERROR;
fn_spec[SUBFONT_MAIN] = tuple ("main");
fn_spec[SUBFONT_ERROR] = tuple ("error");
fn_rewr[SUBFONT_MAIN] = REWRITE_NONE;
fn_rewr[SUBFONT_ERROR] = REWRITE_NONE;
}
int add_font (tree fn, int rewr) {
if (!fn_nr->contains (fn)) {
int sz = N (fn_spec);
fn_nr (fn)= sz;
fn_spec << fn;
fn_rewr << rewr;
// cout << "Create " << sz << " -> " << fn << "\n";
}
return fn_nr[fn];
}
int add_char (tree fn, string c) {
// cout << "Add " << c << " to " << fn << "\n";
add_font (fn, REWRITE_NONE);
int nr= fn_nr[fn];
if (starts (c, "<")) {
if (!cht->contains (c)) cht (c)= nr;
else cht (c)= min (nr, cht[c]);
}
else {
int code= (int) (unsigned char) c[0];
if (chv[code] == -1) chv[code]= nr;
else chv[code]= min (nr, chv[code]);
}
return nr;
}
};
struct smart_font_rep : font_rep {
string mfam;
string family;
string variant;
string series;
string shape;
string rshape;
double sz;
int hdpi;
int dpi;
int math_kind;
int italic_nr;
array<font> fn;
smart_map sm;
array<string> family_tokens;
array<string> given_font;
bool italic_prime_cached;
bool italic_prime_result;
smart_font_rep (string name, font base_fn, font err_fn, string family,
string variant, string series, string shape, double sz,
int hdpi, int vdpi);
font adjust_subfont (font fn);
font get_math_font (string fam, string var, string ser, string sh);
font get_cyrillic_font (string fam, string var, string ser, string sh);
font get_greek_font (string fam, string var, string ser, string sh);
font get_latin_font (string fam, string var, string ser, string sh);
void advance (string s, int& pos, string& r, int& nr);
int resolve (string c, string fam, int attempt);
bool is_italic_prime (string c);
int resolve_rubber (string c, string fam, int attempt);
int resolve (string c);
void initialize_font (int nr);
void maybe_initialize_font (int nr);
int adjusted_dpi (string fam, string var, string ser, string sh, int att);
font make_rubber_font (font base) override;
font get_subfont (string s) override;
bool supports (string c);
void get_extents (string s, metric& ex);
void get_xpositions (string s, SI* xpos);
void get_xpositions (string s, SI* xpos, SI xk);
void draw_fixed (renderer ren, string s, SI x, SI y);
void draw_fixed (renderer ren, string s, SI x, SI y, SI xk);
font magnify (double zoomx, double zoomy);
void advance_glyph (string s, int& pos, bool ligf);
glyph get_glyph (string s);
int index_glyph (string s, font_metric& fnm, font_glyphs& fng);
double get_left_slope (string s);
/**
* 获取字符串右侧的斜率。
*
* 此函数返回给定字符串右侧的倾斜角度,用于光标显示。
* 针对非斜体模式下的CJK字符和数学符号,若斜率小于0.20则强制垂直。
* 同时考虑字体粗体(series)属性,对粗体字体进行特殊处理。
*
* @param s 输入字符串
* @return 右侧斜率值,0.0表示垂直
*/
double get_right_slope (string s);
SI get_left_correction (string s);
SI get_right_correction (string s);
SI get_lsub_correction (string s);
SI get_lsup_correction (string s);
SI get_rsub_correction (string s);
SI get_rsup_correction (string s);
SI get_wide_correction (string s, int mode);
};
bool in_unicode_range (string c, string range);
#endif