mirror of
https://github.com/storytold/harfbuzz.git
synced 2026-11-20 14:31:10 +01:00
[hb-draw] Default to upem font size
This commit is contained in:
1 parent
0fd8261638
commit
008402dccf
4 files changed
+47
-14
No files matched your search
@@ -0,0 +1,10 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 -1900 3335 2400" width="3335" height="2400">
|
||||
<defs>
|
||||
<path id="g1" transform="scale(1 -1)" d="M808,0Q792,32 782,114Q653,-20 474,-20Q314,-20 211.5,70.5Q109,161 109,300Q109,469 237.5,562.5Q366,656 599,656L779,656L779,741Q779,838 721,895.5Q663,953 550,953Q451,953 384,903Q317,853 317,782L131,782Q131,863 188.5,938.5Q246,1014 344.5,1058Q443,1102 561,1102Q748,1102 854,1008.5Q960,915 964,751L964,253Q964,104 1002,16L1002,0L808,0ZM501,141Q588,141 666,186Q744,231 779,303L779,525L634,525Q294,525 294,326Q294,239 352,190Q410,141 501,141Z"/>
|
||||
<path id="g2" transform="scale(1 -1)" d="M1056,529Q1056,281 942,130.5Q828,-20 636,-20Q431,-20 319,125L310,0L140,0L140,1536L325,1536L325,963Q437,1102 634,1102Q831,1102 943.5,953Q1056,804 1056,545L1056,529ZM871,550Q871,739 798,842Q725,945 588,945Q405,945 325,775L325,307Q410,137 590,137Q723,137 797,240Q871,343 871,550Z"/>
|
||||
<path id="g3" transform="scale(1 -1)" d="M574,131Q673,131 747,191Q821,251 829,341L1004,341Q999,248 940,164Q881,80 782.5,30Q684,-20 574,-20Q353,-20 222.5,127.5Q92,275 92,531L92,562Q92,720 150,843Q208,966 316.5,1034Q425,1102 573,1102Q755,1102 875.5,993Q996,884 1004,710L829,710Q821,815 749.5,882.5Q678,950 573,950Q432,950 354.5,848.5Q277,747 277,555L277,520Q277,333 354,232Q431,131 574,131Z"/>
|
||||
</defs>
|
||||
<use href="#g1" transform="translate(0 0)"/>
|
||||
<use href="#g2" transform="translate(1114 0)"/>
|
||||
<use href="#g3" transform="translate(2263 0)"/>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 1.4 KiB |
@@ -2,3 +2,4 @@
|
||||
../../../api/fonts/Roboto-Regular.abc.ttf;--font-size=64;U+0061,U+0062,U+0063;../expected/basic/reuse-svg.svg
|
||||
../../../api/fonts/Roboto-Regular.abc.ttf;--font-size=64 --ned;U+0061,U+0062,U+0063;../expected/basic/flat-svg.svg
|
||||
../../../api/fonts/Roboto-Regular.abc.ttf;--font-size=64 -q;U+0061,U+0020,U+0061;../expected/basic/quiet-paths-space.txt
|
||||
../../../api/fonts/Roboto-Regular.abc.ttf;;U+0061,U+0062,U+0063;../expected/basic/reuse-svg-upem-default.svg
|
||||
+35
-13
@@ -522,6 +522,11 @@ struct draw_output_t : output_options_t<>
|
||||
bbox_t box = compute_bbox (offsets);
|
||||
emit_svg_header (box);
|
||||
|
||||
float font_scale_x = scalbnf ((float) x_scale, -(int) subpixel_bits);
|
||||
float font_scale_y = scalbnf ((float) y_scale, -(int) subpixel_bits);
|
||||
bool upem_scale = font_scale_x == (float) upem &&
|
||||
font_scale_y == (float) upem;
|
||||
|
||||
std::vector<hb_codepoint_t> unique_gids;
|
||||
unique_gids.reserve (128);
|
||||
std::unordered_set<hb_codepoint_t> seen;
|
||||
@@ -536,22 +541,34 @@ struct draw_output_t : output_options_t<>
|
||||
for (hb_codepoint_t gid : unique_gids)
|
||||
{
|
||||
if (!draw_glyph (upem_font, gid, defs_data))
|
||||
fprintf (out_fp, "<path id=\"g%u\" d=\"\"/>\n", gid);
|
||||
fprintf (out_fp,
|
||||
upem_scale
|
||||
? "<path id=\"g%u\" transform=\"scale(1 -1)\" d=\"\"/>\n"
|
||||
: "<path id=\"g%u\" d=\"\"/>\n",
|
||||
gid);
|
||||
else
|
||||
fprintf (out_fp, "<path id=\"g%u\" d=\"%s\"/>\n", gid, path->str);
|
||||
fprintf (out_fp,
|
||||
upem_scale
|
||||
? "<path id=\"g%u\" transform=\"scale(1 -1)\" d=\"%s\"/>\n"
|
||||
: "<path id=\"g%u\" d=\"%s\"/>\n",
|
||||
gid,
|
||||
path->str);
|
||||
}
|
||||
fprintf (out_fp, "</defs>\n");
|
||||
|
||||
g_string_set_size (path, 0);
|
||||
append_num (scalbnf ((float) x_scale, -(int) subpixel_bits), precision, true);
|
||||
g_string_append_c (path, ' ');
|
||||
append_num (-scalbnf ((float) y_scale, -(int) subpixel_bits), precision, true);
|
||||
fprintf (out_fp, "<g transform=\"scale(%s)\">\n", path->str);
|
||||
if (!upem_scale)
|
||||
{
|
||||
g_string_set_size (path, 0);
|
||||
append_num (font_scale_x, precision, true);
|
||||
g_string_append_c (path, ' ');
|
||||
append_num (-font_scale_y, precision, true);
|
||||
fprintf (out_fp, "<g transform=\"scale(%s)\">\n", path->str);
|
||||
|
||||
g_string_set_size (path, 0);
|
||||
int upem_scale_precision = precision < 9 ? 9 : precision;
|
||||
append_num (1.f / upem, upem_scale_precision, true);
|
||||
fprintf (out_fp, "<g transform=\"scale(%s)\">\n", path->str);
|
||||
g_string_set_size (path, 0);
|
||||
int upem_scale_precision = precision < 9 ? 9 : precision;
|
||||
append_num (1.f / upem, upem_scale_precision, true);
|
||||
fprintf (out_fp, "<g transform=\"scale(%s)\">\n", path->str);
|
||||
}
|
||||
|
||||
for (unsigned li = 0; li < lines.size (); li++)
|
||||
{
|
||||
@@ -562,7 +579,10 @@ struct draw_output_t : output_options_t<>
|
||||
g_string_set_size (path, 0);
|
||||
append_num (offset.first + glyph.x, precision, false);
|
||||
g_string_append_c (path, ' ');
|
||||
append_num (offset.second + glyph.y, precision, false);
|
||||
append_num (upem_scale ? -(offset.second + glyph.y)
|
||||
: (offset.second + glyph.y),
|
||||
precision,
|
||||
false);
|
||||
fprintf (out_fp,
|
||||
"<use href=\"#g%u\" transform=\"translate(%s)\"/>\n",
|
||||
glyph.gid,
|
||||
@@ -570,7 +590,9 @@ struct draw_output_t : output_options_t<>
|
||||
}
|
||||
}
|
||||
|
||||
fprintf (out_fp, "</g>\n</g>\n</svg>\n");
|
||||
if (!upem_scale)
|
||||
fprintf (out_fp, "</g>\n</g>\n");
|
||||
fprintf (out_fp, "</svg>\n");
|
||||
}
|
||||
|
||||
void write_flat_svg ()
|
||||
|
||||
+1
-1
@@ -29,7 +29,7 @@
|
||||
#include "shape-consumer.hh"
|
||||
#include "text-options.hh"
|
||||
|
||||
const unsigned DEFAULT_FONT_SIZE = 256;
|
||||
const unsigned DEFAULT_FONT_SIZE = FONT_SIZE_UPEM;
|
||||
const unsigned SUBPIXEL_BITS = 6;
|
||||
|
||||
int
|
||||
|
||||
Reference in new issue
Block a user