Skip to content
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

Merged
merged 4 commits into from
Oct 21, 2024

Conversation

KeShih
Copy link
Contributor

@KeShih KeShih commented Sep 30, 2024

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 in rubber_unicode_font.cpp and unicode_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 run xmake run parse_variant_test to test parse_variant(string, string) function.

Before:
image
After:
The first two are OpenType fonts affected by this change, while the latter two are hardcoded OpenType fonts that remain unchanged.
image

@KeShih KeShih force-pushed the glyph-variant branch 2 times, most recently from 2cbef38 to ae96369 Compare October 15, 2024 07:59
@KeShih KeShih marked this pull request as ready for review October 20, 2024 12:44
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))
Copy link
Contributor

@da-liii da-liii Oct 20, 2024

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++) {
Copy link
Contributor

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);
Copy link
Contributor

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;
Copy link
Contributor

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;
Copy link
Contributor

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);
Copy link
Contributor

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) * ">";
Copy link
Contributor

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

@da-liii
Copy link
Contributor

da-liii commented Oct 20, 2024

Suggested title change: Using OpenType glyph variants for rubber character

@da-liii
Copy link
Contributor

da-liii commented Oct 20, 2024

You may add the following description for your What section:

Defined in smart_font.cpp:

static bool
is_rubber (string c) {
  return (starts (c, "<large-") || starts (c, "<left-") ||
          starts (c, "<right-") || starts (c, "<mid-")) &&
         ends (c, ">");
}

A rubber character is represented as <xxxx> and the xxxx part must starts from large-, left-, right- and mid-.

This pull request introduced a mechanism to render the rubber character (rubber symbol) using <@xxxx>. bla bla bla

@da-liii
Copy link
Contributor

da-liii commented Oct 20, 2024

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
Copy link
Contributor

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);
Copy link
Contributor

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) {
Copy link
Contributor

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

Copy link
Contributor

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);
Copy link
Contributor

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;
}
Copy link
Contributor

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-

@KeShih KeShih changed the title [80_7] Using OpenType glyph variants [80_7] Using OpenType glyph variants for rubber character Oct 21, 2024
@KeShih
Copy link
Contributor Author

KeShih commented Oct 21, 2024

Is this issue #1682 fixed by this pull request?

This PR does not fix this issue.

Copy link
Contributor

@da-liii da-liii left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@KeShih KeShih merged commit e2d5c20 into XmacsLabs:branch-1.2 Oct 21, 2024
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants