Re: [HarfBuzz] Zero-width joiner has width
On 08/08/2015 16:31, Behdad Esfahbod wrote: The 'm' has advance of 1645 units in a 2048-unit font. At 10pt, that means: 1645 / 2048. * 10 8.0322265625 So we're losing something on the way. How do you setup the font scale? Show me the code. In general, for something like Sile, you probably want to shape text at the upem size to have on precision loss whatsoever. OK, I'm now trying to set the scaling to the font upem, but I'm not getting that working either. Assuming an incoming FT_Face face: hb_ft_font = hb_ft_font_create(face, NULL); hb_face_t* hbFace = hb_font_get_face(hb_ft_font); /* Attempt to set upem scale */ unsigned int upem = hb_face_get_upem(hbFace); hb_font_set_scale(hb_ft_font, upem, upem); printf(upem = %i\n, upem); This prints upem = 2048; so far so good. Now after shaping: ... shape_plan = hb_shape_plan_create_cached(hbFace, segment_props, features, nFeatures, NULL); int res = hb_shape_plan_execute(shape_plan, hb_ft_font, buf, features, nFeatures); glyph_info = hb_buffer_get_glyph_infos(buf, glyph_count); glyph_pos= hb_buffer_get_glyph_positions(buf, glyph_count); ... lua_pushstring(L, x_advance); lua_pushnumber(L, glyph_pos[j].x_advance); lua_settable(L, -3); ... { { codepoint = 77, depth = 0, height = 4.6875, name = m, x_advance = 514, }, } Should be 1645, right? I am not sure where 514 is coming from. The full shaper code is at https://github.com/simoncozens/sile/blob/master/src/justenoughharfbuzz.c#L292 ___ HarfBuzz mailing list HarfBuzz@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/harfbuzz
Re: [HarfBuzz] Zero-width joiner has width
On 15-08-09 10:15 AM, Simon Cozens wrote: { { codepoint = 77, depth = 0, height = 4.6875, name = m, x_advance = 514, }, } Should be 1645, right? I am not sure where 514 is coming from. So what was the problem? ___ HarfBuzz mailing list HarfBuzz@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/harfbuzz
Re: [HarfBuzz] Zero-width joiner has width
How do you measure? When I get time to build Sile, I'm first going to remove FreeType dep... On Aug 9, 2015 4:58 PM, Simon Cozens si...@simon-cozens.org wrote: On 09/08/2015 09:15, Simon Cozens wrote: OK, I'm now trying to set the scaling to the font upem, but I'm not getting that working either. After a bit of fiddling I have now got it working, using: hb_face_t* hbFace = hb_ft_face_create_cached(face); hb_ft_font = hb_font_create (hbFace); unsigned int upem = hb_face_get_upem(hbFace); hb_font_set_scale(hb_ft_font, upem, upem); hb_ft_font_set_funcs(hb_ft_font); It's about 50% slower than using Freetype functions directly, which is a big shame(!), but computers always get faster and I'm sure this way gives me more flexibility later... See latest version: https://github.com/simoncozens/sile/blob/master/src/justenoughharfbuzz.c#L263 ___ HarfBuzz mailing list HarfBuzz@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/harfbuzz
Re: [HarfBuzz] Zero-width joiner has width
On 09/08/2015 09:15, Simon Cozens wrote: OK, I'm now trying to set the scaling to the font upem, but I'm not getting that working either. After a bit of fiddling I have now got it working, using: hb_face_t* hbFace = hb_ft_face_create_cached(face); hb_ft_font = hb_font_create (hbFace); unsigned int upem = hb_face_get_upem(hbFace); hb_font_set_scale(hb_ft_font, upem, upem); hb_ft_font_set_funcs(hb_ft_font); It's about 50% slower than using Freetype functions directly, which is a big shame(!), but computers always get faster and I'm sure this way gives me more flexibility later... See latest version: https://github.com/simoncozens/sile/blob/master/src/justenoughharfbuzz.c#L263 ___ HarfBuzz mailing list HarfBuzz@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/harfbuzz
Re: [HarfBuzz] Zero-width joiner has width
On 8/8/15 15:50, Simon Cozens wrote: On 08/08/2015 15:25, Behdad Esfahbod wrote: Ok, that makes sense. And yes, I was ignoring the advance for glyphs and instead using Freetype to return the glyph width. I think I stole that bit of code from xetex. :-) Really? It may not be totally true. I don't know if XeTeX ignores the advance data - it probably doesn't Yeah, I'd be really surprised if it did -- that would break kerning, for example. I think someone would probably have noticed by now. :) - but I certainly stole the glyph bounds measurement code from XeTeXFontInst::getGlyphBounds. However, when I replace SILE's glyph width measurement code with 'glyph_pos[j].x_advance / 64.0' instead of getting the glyph advance out of Freetype, I get slightly different output. With Harfbuzz's x_advance, a Gentium letter m at 10pt measures as 8.03125pt wide; using the width information from Freetype, I get 8.0322265625pt. I can't account for the discrepancy and I don't know who is right. According to the hmtx table, at least in the version I happen to be looking at, m has a width of 1645 units. The font has 2048 units per em; so at 10pt, that works out to 10*1645/2048 = 8.03222656pt. So FreeType seems to be telling you the truth; but that doesn't mean harfbuzz is wrong, necessarily. It sounds like you're using 26.6 fixed-point values in harfbuzz, in which case you can only expect 6 binary digits of fractional precision. So I'd expect the value you'll be getting from glyph_pos[j].x_advance to be round(10*1645*64/2048) which comes to 512, and 512/64.0 is indeed 8.03125. For higher precision, you might want to consider using 16.16 rather than 26.6 fixed-point arithmetic. JK ___ HarfBuzz mailing list HarfBuzz@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/harfbuzz
Re: [HarfBuzz] Zero-width joiner has width
On 15-08-08 04:50 PM, Simon Cozens wrote: On 08/08/2015 15:25, Behdad Esfahbod wrote: Ok, that makes sense. And yes, I was ignoring the advance for glyphs and instead using Freetype to return the glyph width. I think I stole that bit of code from xetex. :-) Really? It may not be totally true. I don't know if XeTeX ignores the advance data - it probably doesn't - but I certainly stole the glyph bounds measurement code from XeTeXFontInst::getGlyphBounds. Why do you need the bounds BTW? Use hb_font_get_glyph_extents() instead, let me know if it doesn't help. However, when I replace SILE's glyph width measurement code with 'glyph_pos[j].x_advance / 64.0' instead of getting the glyph advance out of Freetype, I get slightly different output. Need details. With Harfbuzz's x_advance, a Gentium letter m at 10pt measures as 8.03125pt wide; using the width information from Freetype, I get 8.0322265625pt. I can't account for the discrepancy and I don't know who is right. The 'm' has advance of 1645 units in a 2048-unit font. At 10pt, that means: 1645 / 2048. * 10 8.0322265625 So we're losing something on the way. How do you setup the font scale? Show me the code. In general, for something like Sile, you probably want to shape text at the upem size to have on precision loss whatsoever. b ___ HarfBuzz mailing list HarfBuzz@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/harfbuzz
Re: [HarfBuzz] Zero-width joiner has width
On Sat, Aug 08, 2015 at 04:25:07PM +0200, Behdad Esfahbod wrote: On 15-08-02 07:42 PM, Simon Cozens wrote: On Aug 2, 2015, at 18:08, Jonathan Kew jfkth...@gmail.com wrote: Which suggests there's something odd about how you're using harfbuzz. Ok, that makes sense. And yes, I was ignoring the advance for glyphs and instead using Freetype to return the glyph width. I think I stole that bit of code from xetex. :-) Really? Khaled, what's that about? I don’t think XeTeX ever did this. Regards, Khaled b ___ HarfBuzz mailing list HarfBuzz@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/harfbuzz
Re: [HarfBuzz] Zero-width joiner has width
On Aug 2, 2015, at 18:08, Jonathan Kew jfkth...@gmail.com wrote: Which suggests there's something odd about how you're using harfbuzz. Ok, that makes sense. And yes, I was ignoring the advance for glyphs and instead using Freetype to return the glyph width. I think I stole that bit of code from xetex. :-) ___ HarfBuzz mailing list HarfBuzz@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/harfbuzz