-
Notifications
You must be signed in to change notification settings - Fork 34
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[80_7] Using OpenType glyph variants for rubber character #2119
Conversation
2cbef38
to
ae96369
Compare
src/Graphics/Fonts/smart_font.cpp
Outdated
if (fn[nr]->supports (c)) return sm->add_char (key, c); | ||
} | ||
return -1; | ||
} | ||
|
||
font | ||
smart_font_rep::make_rubber_font (font base) { | ||
if (occurs ("mathlarge=", res_name) || occurs ("mathrubber=", res_name)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: use contains
instead of occurs
for better readability
@@ -71,10 +89,16 @@ rubber_unicode_font_rep::rubber_unicode_font_rep (string name, font base2) | |||
//<< ((double) (ex->y2-ex->y1)) / base->yx << LF; | |||
if ((((double) (ex->y2 - ex->y1)) / base->yx) >= 1.55) big_sums= true; | |||
} | |||
for (int i= 0; i < 5; i++) { | |||
|
|||
for (int i= 0; i < 6; i++) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use const and add comment on the magic number 6
parse_variant (string s, string& r) { | ||
// cout << "parse_variant for " << s << LF; | ||
int var = 0; | ||
int n = N (s); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: typically, we use s_N for N(s)
, it is ok to use n here, because there only one N() invoke
|
||
int j= 0; | ||
unsigned int u= decode_from_utf8 (uu, j); | ||
cout << "unicode " << uu << " -> " << lolly::data::to_hex (u) << LF; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should be guarded by debug switch
|
||
unsigned int glyphID= ft_get_char_index (math_face->ft_face, u); | ||
|
||
cout << "search_font_sub_opentype for " << u << " -> " << glyphID << LF; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should be guarded by debug switch
int metric_to_design_unit (SI m); | ||
}; | ||
|
||
font rubber_unicode_font (font base, tt_face face); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add the last empty line
if (var < N (gv)) { | ||
int res= gv[var]; | ||
// use <@XXXX> for native glyph id | ||
rew= "<@" * as_hexadecimal (res, 4) * ">"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
a very important design, needs to be documented carefully
Suggested title change: Using OpenType glyph variants for rubber character |
You may add the following description for your Defined in smart_font.cpp:
A rubber character is represented as This pull request introduced a mechanism to render the rubber character (rubber symbol) using |
Is this issue #1682 fixed by this pull request? |
rubber_unicode_font_rep::search_font_sub_opentype (string s, string& rew) { | ||
string r; | ||
int var= 0; | ||
bool ver= true; // verizontal or vertical, default is vertical |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
verizontal -> horizontal
use a longer variable name like using_vertical
instead of ver
, ver
is usually short for version
string uu= N (r) > 1 ? strict_cork_to_utf8 ("<" * r * ">") : r; | ||
|
||
int j= 0; | ||
unsigned int u= decode_from_utf8 (uu, j); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use uint32_t here, unsigned int is not in fixed bytes
@@ -105,6 +133,77 @@ rubber_unicode_font_rep::get_font (int nr) { | |||
* Find the font | |||
******************************************************************************/ | |||
|
|||
int | |||
parse_variant (string s, string& r) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unit tests should be added for parse_variant, if you add unit tests for it, you do not need to add the static
modifier
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what is r, what is the return code, they should be documented
int var = 0; | ||
int n = N (s); | ||
int start= search_forwards ("-", 0, s); | ||
int end = search_backwards ("-", n, s); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tokenize provided in analyze.hpp is a better choice to impl this routine
Here is the function definition of tokenize
:
array<string> tokenize (string s, string sep);
} | ||
else if (starts (s, "<wide-")) { | ||
ver= false; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TODO might be added here for <left-
, <right-
, <mid-
This PR does not fix this issue. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
What?
Utilizing the glyph variant table of OpenType fonts to improve typesetting, specifically, it primarily enhances the typesetting of large mathematical operators. However, some glyph are not included in the table, so they will not be improved.
OpenType glyph variant table provides the glyph IDs for the variants, so we introduced
<@xxxx>
, which translates the glyph ID into a 4-digit hexadecimal number for representation. This mechanism is only used inrubber_unicode_font.cpp
andunicode_font.cpp
.Why?
For many OpenType fonts, such as Asana Math, certain large operators use incorrect fonts or glyphs.
How to test it?
Open
devel/80_7.tmu
and runxmake run parse_variant_test
to testparse_variant(string, string)
function.Before:
After:
The first two are OpenType fonts affected by this change, while the latter two are hardcoded OpenType fonts that remain unchanged.