[python-win32] [DirectWrite] How to obtain fonts path via pywin32?
Moi15 Moi
moi15moismokerlolilol at gmail.com
Sun Apr 23 10:01:15 EDT 2023
Hi
Is there a way to obtain the font path via pywin32? I need to communicate
with DirectWrite.
Here is the algorithm I would need to be able to get the fonts path based
on the microsoft documentation:
# DWriteCreateFactory -
https://learn.microsoft.com/en-us/windows/win32/api/dwrite/nf-dwrite-dwritecreatefactory
# IDWriteFactory3 -
https://learn.microsoft.com/en-us/windows/win32/api/dwrite_3/nn-dwrite_3-idwritefactory3
write_factory =
DWriteCreateFactory(DWRITE_FACTORY_TYPE.DWRITE_FACTORY_TYPE_ISOLATED,
__uuidof(IDWriteFactory3), False)
# GetSystemFontSet -
https://learn.microsoft.com/en-us/windows/win32/api/dwrite_3/nf-dwrite_3-idwritefactory3-getsystemfontset
font_set = write_factory.GetSystemFontSet()
# GetFontCount -
https://learn.microsoft.com/en-us/windows/win32/api/dwrite_3/nf-dwrite_3-idwritefontset-getfontcount
for i in range(font_set.GetFontCount()):
# GetFontFaceReference -
https://learn.microsoft.com/en-us/windows/win32/api/dwrite_3/nf-dwrite_3-idwritefontset-getfontfacereference
font_face_reference = font_set.GetFontFaceReference(i)
# GetFontFile -
https://learn.microsoft.com/en-us/windows/win32/api/dwrite_3/nf-dwrite_3-idwritefontfacereference-getfontfile
font_file = font_face_reference.GetFontFile()
# GetReferenceKey -
https://learn.microsoft.com/en-us/windows/win32/api/dwrite/nf-dwrite-idwritefontfile-getreferencekey
reference_key, reference_key_size = font_file.GetReferenceKey()
# GetFilePathFromKey -
https://learn.microsoft.com/en-us/windows/win32/directwrite/idwritelocalfontfileloader-getfilepathfromkey
path = GetFilePathFromKey(reference_key, reference_key_size)
Have a nice day
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.python.org/pipermail/python-win32/attachments/20230423/ada32d27/attachment.html>
More information about the python-win32
mailing list