[HarfBuzz] How to get hb_face_t and hb_font_t without Freetype?
Behdad Esfahbod
behdad at behdad.org
Fri May 24 16:18:06 UTC 2019
Also font-funcs if you can contribute those.
On Fri, May 24, 2019 at 12:17 PM Behdad Esfahbod <behdad at behdad.org> wrote:
> Thanks Konstantin!
>
> Should this become a hb-uniscribe (or hb-gdi?) API?
>
> On Fri, May 24, 2019 at 12:17 PM Konstantin Ritt <ritt.ks at gmail.com>
> wrote:
>
>> hb_blob_t *my_reference_table(hb_face_t * /*face*/, hb_tag_t tag, void *user_data)
>>
>> {
>>
>> HDC hdc = (HDC)user_data;
>>
>> SelectObject(hdc, hfont);
>>
>>
>> char *buffer = NULL;
>>
>> DWORD length = 0;
>>
>> length = GetFontData(hdc, byte_swap<DWORD>(tag), 0, buffer, length);
>>
>> if (length == GDI_ERROR)
>>
>> return hb_blob_get_empty();
>>
>>
>> buffer = (char *)::malloc(length);
>>
>> length = GetFontData(hdc, byte_swap<DWORD>(tag), 0, buffer, length);
>>
>> if (length == GDI_ERROR)
>>
>> length = 0;
>>
>>
>> return hb_blob_create((const char *)buffer, length, HB_MEMORY_MODE_READONLY, buffer, ::free);
>>
>> }
>>
>>
>> hb_face_t *my_face_create_from_hdc(HDC hdc)
>>
>> {
>>
>> return hb_face_create_for_tables(my_reference_table, (void *)hdc, NULL);
>>
>> }
>>
>>
>>
>>
>> Regards,
>> Konstantin
>>
>>
>> пт, 24 мая 2019 г. в 16:39, Eli Zaretskii <eliz at gnu.org>:
>>
>>> > From: Ebrahim Byagowi <ebraminio at gmail.com>
>>> > Date: Fri, 24 May 2019 20:13:43 +0430
>>> > Cc: Harfbuzz <harfbuzz at lists.freedesktop.org>
>>> >
>>> > Pardon me for the may inaccurate following answer I have to write
>>> quickly,
>>>
>>> Thanks for your help.
>>>
>>> > > Also, does HarfBuzz support TrueType Collection (TTC) files, and if
>>> so, does it want the data only for the
>>> > currently selected font or all
>>> > of the data?
>>> >
>>> > It does, if you want harfbuzz handles it for you, you should give it
>>> the full blob and set the index you like in
>>> > second argument of hb_face_create, otherwise you should handle it
>>> yourself.
>>>
>>> OK, this brings me to another question: what should I in general pass
>>> as the 2nd argument of hb_face_create? Suppose I'm using a TTF or OTF
>>> font file, should I always pass zero as the 2nd argument? What is the
>>> semantics of that argument?
>>>
>>> > > I'm now working on the HarfBuzz font driver for Emacs on Windows
>>> using GetFontData with the dwTable
>>> > argument zero, to get the entire data of the font.
>>> >
>>> > Is it DirectWrite? Have you seen the helper we have the in
>>> hb-directwrite.h and hb-uniscribe.h? They can be
>>> > very useful.
>>>
>>> I'm not using DirectWrite, nor am I using Uniscribe. My HarfBuzz is
>>> built without these two, as I understand building with these back-ends
>>> is only needed for comparison. I want to use the HarfBuzz shaper, and
>>> only it (Emacs already has support for Uniscribe).
>>>
>>> But yes, I do consult these files to figure out answers to my
>>> questions.
>>>
>>> > > does their memory need to be freed in some manner after I have the
>>> hb_font_t object, or do I have to keep
>>> > them as long as hb_font_t is in use?
>>> >
>>> > Don't free it yourself specially if in use, you can use harfbuzz
>>> destroy callback so harfbuzz can handle it for
>>> > you.
>>>
>>> Sorry, I don't think I understand: what do you mean by "harfbuzz
>>> destroy callback"? If you mean the 'destroy" argument of
>>> hb_blob_create, then AFAIU this is called only to destroy user_data,
>>> and I don't have user_data, I pass NULL as the 4th argument of
>>> hb_blob_create. And hb_face_create doesn't have any callback argument
>>> at all.
>>>
>>> I see in the few programs in util/ that both the blob and the face are
>>> destroyed as soon as hb_font_t object is created, which is why I
>>> thought I could do the same. But now you seem to say I shouldn't?
>>>
>>> For that matter, what should I use as the 'mode' argument of
>>> hb_blob_create?
>>>
>>> This page:
>>>
>>> https://harfbuzz.github.io/object-model-blobs.html
>>>
>>> shows an example of calling hb_blob_create with 'free' (in my case,
>>> 'xfree') as the 'destroy' callback, so I guess my interpretation of
>>> that argument as being pertinent to user_data was incorrect? Still,
>>> the questions about memory management for hb_face_t and about the
>>> semantics of the hb_memory_mode_t enum values are left unanswered.
>>>
>>> > > I see that hb_blob_create, hb_face_create etc. return empty objects
>>> when they fail. But I see no "is-empty"
>>> > function or macro in the docs, did I miss something?
>>> >
>>> > Some of the objects may work with empty comparison but it is not
>>> broken face
>>> > https://github.com/harfbuzz/harfbuzz/issues/1572 but something does
>>> it very accurately is
>>> > hb_face_get_glyph_count
>>>
>>> AFAIU, you are saying that if hb_face_get_glyph_count returns zero,
>>> the face is empty and shouldn't be used, is that right?
>>>
>>> > > Where do those 64.0 factors come from?
>>> >
>>> > Subpixel accuracy, harfbuzz works with integers but as subpixel
>>> accuracy needed you have to we need to do
>>> > some scaling. Scaling is not the pixels but _set_ppem and _set_ptem is
>>> (this is very inaccurate, but I hope
>>> > would be useful)
>>>
>>> Does this mean I should use the factor of 64 in my code as well? Or
>>> does that value depend on some properties of the font?
>>>
>>> >
>>> > > Or point me to the documentation where that is described, if I
>>> missed it?
>>> >
>>> > https://harfbuzz.github.io/ may address some of your issues
>>>
>>> Thanks again for your help.
>>> _______________________________________________
>>> HarfBuzz mailing list
>>> HarfBuzz at lists.freedesktop.org
>>> https://lists.freedesktop.org/mailman/listinfo/harfbuzz
>>
>> _______________________________________________
>> HarfBuzz mailing list
>> HarfBuzz at lists.freedesktop.org
>> https://lists.freedesktop.org/mailman/listinfo/harfbuzz
>
>
>
> --
> behdad
> http://behdad.org/
>
--
behdad
http://behdad.org/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.freedesktop.org/archives/harfbuzz/attachments/20190524/f56d08d5/attachment.html>
More information about the HarfBuzz
mailing list