1 2 /****************************************************************************** 3 * MODULE : font.hpp 4 * DESCRIPTION: fonts 5 * COPYRIGHT : (C) 1999 Joris van der Hoeven 6 ******************************************************************************* 7 * This software falls under the GNU general public license version 3 or later. 8 * It comes WITHOUT ANY WARRANTY WHATSOEVER. For details, see the file LICENSE 9 * in the root directory or <http://www.gnu.org/licenses/gpl-3.0.html>. 10 ******************************************************************************/ 11 12 #ifndef FONT_H 13 #define FONT_H 14 #include "space.hpp" 15 #include "renderer.hpp" 16 17 RESOURCE(font); 18 19 struct glyph; 20 21 #define FONT_TYPE_TEX 0 22 #define FONT_TYPE_UNICODE 1 23 #define FONT_TYPE_QT 2 24 #define FONT_TYPE_OTHER 3 25 26 #define START_OF_LINE 1 27 #define END_OF_LINE 2 28 #define PROTRUSION_MASK 60 29 #define CJK_PROTRUSION_MASK 28 30 #define QUANJIAO 4 31 #define BANJIAO 8 32 #define HANGMOBANJIAO 12 33 #define KAIMING 16 34 #define WESTERN_PROTRUSION 32 35 #define TABLE_CELL 64 36 37 /****************************************************************************** 38 * The font structure 39 ******************************************************************************/ 40 41 struct font_rep: rep<font> { 42 int type; // font type 43 SI size; // requested size 44 SI design_size; // design size in points/256 45 SI display_size; // display size in points/PIXEL 46 double slope; // italic slope 47 space spc; // usual space between words 48 space extra; // extra space at end of words 49 SI sep; // separation space between close components 50 51 SI y1; // bottom y position 52 SI y2; // top y position 53 SI yx; // height of the x character 54 SI yfrac; // vertical position fraction bar 55 SI ysub_lo_base; // base line for subscripts 56 SI ysub_hi_lim; // upper limit for subscripts 57 SI ysup_lo_lim; // lower limit for supscripts 58 SI ysup_lo_base; // base line for supscripts 59 SI ysup_hi_lim; // upper limit for supscripts 60 SI yshift; // vertical script shift inside fractions 61 62 SI wpt; // width of one point in font 63 SI wfn; // wpt * design size in points 64 SI wline; // width of fraction bars and so 65 SI wquad; // quad space (often width of widest character M) 66 67 double last_zoom; // last rendered zoom 68 font zoomed_fn; // zoomed font for last_zoom (or nil) 69 70 hashmap<int,int> protrusion_maps; // tables for protrusion 71 72 font_rep (string name); 73 font_rep (string name, font fn); 74 void copy_math_pars (font fn); 75 76 virtual bool supports (string c) = 0; 77 virtual void get_extents (string s, metric& ex) = 0; 78 virtual void get_extents (string s, metric& ex, bool ligf); 79 virtual void get_extents (string s, metric& ex, SI xk); 80 virtual void get_xpositions (string s, SI* xpos); 81 virtual void get_xpositions (string s, SI* xpos, bool ligf); 82 virtual void get_xpositions (string s, SI* xpos, SI xk); 83 virtual void draw_fixed (renderer ren, string s, SI x, SI y) = 0; 84 virtual void draw_fixed (renderer ren, string s, SI x, SI y, bool ligf); 85 virtual void draw_fixed (renderer ren, string s, SI x, SI y, SI xk); 86 virtual font magnify (double zoom) = 0; 87 virtual void draw (renderer ren, string s, SI x, SI y, SI xk, bool ext); 88 virtual void draw (renderer ren, string s, SI x, SI y); 89 virtual void draw (renderer ren, string s, SI x, SI y, SI xk); 90 91 virtual double get_left_slope (string s); 92 virtual double get_right_slope (string s); 93 virtual SI get_left_correction (string s); 94 virtual SI get_right_correction (string s); 95 virtual SI get_left_protrusion (string s, int mode); 96 virtual SI get_right_protrusion (string s, int mode); 97 98 void var_get_extents (string s, metric& ex); 99 void var_get_xpositions (string s, SI* xpos); 100 void var_draw (renderer ren, string s, SI x, SI y); 101 virtual glyph get_glyph (string s); 102 }; 103 104 string default_chinese_font_name (); 105 string default_japanese_font_name (); 106 string default_korean_font_name (); 107 108 font error_font (font fn); 109 font virtual_font (font base, string family, int size, int dpi); 110 font tt_font (string family, int size, int dpi); 111 font unicode_font (string family, int size, int dpi); 112 font unicode_math_font (font up, font it, font bup, font bit, font fb); 113 font rubber_unicode_font (font base); 114 font rubber_stix_font (font base); 115 font rubber_assemble_font (font base); 116 font rubber_font (font base); 117 font x_font (string family, int size, int dpi); 118 font qt_font (string family, int size, int dpi); 119 font tex_font (string fam, int size, int dpi, int dsize=10); 120 font tex_cm_font (string fam, int size, int dpi, int dsize=10); 121 font tex_ec_font (string fam, int size, int dpi, int dsize=10); 122 font tex_la_font (string fam, int size, int dpi, int dsize=10); 123 font tex_gr_font (string fam, int size, int dpi, int dsize=10); 124 font tex_adobe_font (string fam, int size, int dpi, int dsize=10); 125 font tex_rubber_font (string trl_name, 126 string fam, int size, int dpi, int dsize=10); 127 font tex_dummy_rubber_font (font base_fn); 128 129 void font_rule (tree which, tree by); 130 font find_font (scheme_tree t); 131 font find_magnified_font (scheme_tree t, double zf); 132 font find_font (string family, string fn_class, 133 string series, string shape, int sz, int dpi); 134 bool find_closest (string& family, string& variant, 135 string& series, string& shape, int attempt= 1); 136 font closest_font (string family, string variant, string series, string shape, 137 int sz, int dpi, int attempt= 1); 138 139 font math_font (scheme_tree t, font base_fn, font error_fn, double zoom= 1.0); 140 font compound_font (scheme_tree def, double zoom= 1.0); 141 font smart_font (string family, string variant, string series, string shape, 142 int sz, int dpi); 143 font smart_font (string family, string variant, string series, string shape, 144 string tf, string tv, string tw, string ts, int sz, int dpi); 145 146 int script (int sz, int level); 147 148 // Font database 149 extern bool new_fonts; 150 void set_new_fonts (bool new_val); 151 bool get_new_fonts (); 152 void font_database_build (url u); 153 void font_database_build_local (); 154 void font_database_build_global (); 155 void font_database_build_global (url u); 156 void font_database_build_characteristics (bool force); 157 void font_database_load (); 158 void font_database_global_load (); 159 void font_database_save (); 160 void font_database_filter (); 161 void font_database_save_local_delta (); 162 array<string> font_database_families (); 163 array<string> font_database_delta_families (); 164 array<string> font_database_styles (string family); 165 array<string> font_database_global_styles (string family); 166 array<string> font_database_search (string family, string style); 167 array<string> font_database_search (string fam, string var, 168 string series, string shape); 169 array<string> font_database_characteristics (string family, string style); 170 tree font_database_substitutions (string family); 171 172 // Font selection 173 tree array_as_tuple (array<string> a); 174 array<string> tuple_as_array (tree t); 175 string encode_feature (string s); 176 string family_to_master (string f); 177 array<string> master_to_families (string f); 178 array<string> master_features (string m); 179 array<string> family_features (string f); 180 array<string> family_strict_features (string f); 181 array<string> style_features (string s); 182 array<string> logical_font (string family, string shape); 183 array<string> logical_font_exact (string family, string style); 184 array<string> logical_font (string f, string v, string ser, string sh); 185 array<string> guessed_features (string family, string shape); 186 array<string> guessed_features (string family, bool pure_guess); 187 double guessed_distance (string fam1, string sty1, string fam2, string sty2); 188 double guessed_distance (string master1, string master2); 189 string get_family (array<string> v); 190 string get_variant (array<string> v); 191 string get_series (array<string> v); 192 string get_shape (array<string> v); 193 array<string> search_font (array<string> v, int attempt= 1); 194 array<string> search_font_exact (array<string> v); 195 array<string> search_font_families (array<string> v); 196 array<string> search_font_styles (string s, array<string> v); 197 array<string> patch_font (array<string> v, array<string> w, bool decode= true); 198 array<string> apply_substitutions (array<string> v); 199 string main_family (string f); 200 201 #endif // defined FONT_H 202