Skip to content

Commit

Permalink
Try another strategy to get hb font
Browse files Browse the repository at this point in the history
  • Loading branch information
liZe committed Apr 18, 2024
1 parent 5738701 commit 27a8608
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 13 deletions.
24 changes: 16 additions & 8 deletions .github/workflows/exe.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,25 @@ jobs:
- uses: actions/setup-python@v5
with:
python-version: '3.12'
- name: Install Pango (Windows)
- name: Use absolute imports and install Pango (Windows)
run: |
C:\msys64\usr\bin\bash -lc 'pacman -S mingw-w64-x86_64-pango --noconfirm'
C:\msys64\usr\bin\bash -lc 'pacman -S mingw-w64-x86_64-pango mingw-w64-x86_64-sed --noconfirm'
C:\msys64\mingw64\bin\sed -i 's/^from \. /from weasyprint /' weasyprint/__main__.py
C:\msys64\mingw64\bin\sed -i 's/^from \./from weasyprint\./' weasyprint/__main__.py
echo "C:\msys64\mingw64\bin" | Out-File -FilePath $env:GITHUB_PATH
rm C:\msys64\mingw64\bin\python.exe
- name: Compile script (Windows)
run: |
C:\msys64\mingw64\bin\gcc testfont.c -o testfont '--%' $(C:\msys64\mingw64\bin\pkg-config.exe --cflags --libs pango fontconfig harfbuzz pangoft2)
.\testfont.exe
- name: Install requirements
run: python -m pip install . pyinstaller
- name: Generate executable
run: python -m PyInstaller weasyprint/__main__.py -n weasyprint -F
- name: Test executable
run: dist/weasyprint --info
- name: Store executable
uses: actions/upload-artifact@v4
with:
name: testfont
path: testfont.exe
name: weasyprint-windows
path: |
dist/weasyprint
dist/weasyprint.exe
README.rst
LICENSE
9 changes: 5 additions & 4 deletions weasyprint/pdf/stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,21 @@
from ..logger import LOGGER
from ..matrix import Matrix
from ..text.constants import PANGO_STRETCH_PERCENT
from ..text.ffi import ffi, harfbuzz, pango, units_to_double
from ..text.ffi import ffi, harfbuzz, pango, pangoft2, units_to_double


class Font:
def __init__(self, pango_font):
hb_font = pango.pango_font_get_hb_font(pango_font)
print('font', hb_font)
hb_face = harfbuzz.hb_font_get_face(hb_font)
fc_font = ffi.cast('PangoFcFont *', pango_font)
fontmap = ffi.cast('PangoFcFontMap *', pango.pango_font_get_font_map(pango_font))
hb_face = pangoft2.pango_fc_font_map_get_hb_face(fontmap, fc_font)
print('face', hb_face)
hb_blob = harfbuzz.hb_face_reference_blob(hb_face)
print('blob', hb_blob)
with ffi.new('unsigned int *') as length:
hb_data = harfbuzz.hb_blob_get_data(hb_blob, length)
print('length', length[0])
print(hb_data, ffi.NULL)
self.file_content = ffi.unpack(hb_data, int(length[0]))
harfbuzz.hb_blob_destroy(hb_blob)
self.index = harfbuzz.hb_face_get_index(hb_face)
Expand Down
5 changes: 4 additions & 1 deletion weasyprint/text/ffi.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@
void pango_font_description_free (PangoFontDescription *desc);
PangoFontDescription * pango_font_description_copy (
const PangoFontDescription *desc);
PangoFontMap* pango_font_get_font_map (PangoFont* font);
void pango_font_description_set_family (
PangoFontDescription *desc, const char *family);
void pango_font_description_set_style (
Expand Down Expand Up @@ -390,12 +390,15 @@
// PangoFT2
typedef ... PangoFcFont;
typedef ... PangoFcFontMap;
PangoFontMap * pango_ft2_font_map_new (void);
void pango_fc_font_map_set_config (
PangoFcFontMap *fcfontmap, FcConfig *fcconfig);
void pango_fc_font_map_config_changed (PangoFcFontMap *fcfontmap);
hb_face_t* pango_fc_font_map_get_hb_face (
PangoFcFontMap* fcfontmap, PangoFcFont* fcfont);
''')


Expand Down

0 comments on commit 27a8608

Please sign in to comment.