Skip to content

Commit

Permalink
Merge pull request #1644 from Kozea/bitmap-fonts
Browse files Browse the repository at this point in the history
Bitmap fonts
  • Loading branch information
liZe authored Jun 17, 2022
2 parents e38bff8 + 2190f68 commit d8533da
Show file tree
Hide file tree
Showing 6 changed files with 307 additions and 106 deletions.
7 changes: 2 additions & 5 deletions docs/api_reference.rst
Original file line number Diff line number Diff line change
Expand Up @@ -184,11 +184,8 @@ are automatically embedded in PDF files.
Pango always uses fontconfig to access fonts, even on Windows and macOS. You
can list the available fonts thanks to the ``fc-list`` command, and know which
font is matched by a given pattern thanks to ``fc-match``. Copying a font file
into the ``~/.local/share/fonts`` or ``~/.fonts`` directory is generally enough
to install a new font. WeasyPrint should support `any font format handled by
FreeType`_.

.. _any font format handled by FreeType: https://en.wikipedia.org/wiki/FreeType#File_formats
into the ``~/.local/share/fonts`` directory is generally enough to install a
new font. WeasyPrint should support the major font formats handled by Harfbuzz.


CSS
Expand Down
28 changes: 28 additions & 0 deletions tests/draw/test_text.py
Original file line number Diff line number Diff line change
Expand Up @@ -743,3 +743,31 @@ def test_tabulation_character(assert_pixels):
}
</style>
<pre>a&Tab;b</pre>''')


def test_otb_font(assert_pixels):
assert_pixels('''
____________________
__RR______RR________
__RR__RR__RR________
__RR__RR__RR________
____________________
____________________
''', '''
<style>
@page {
size: 20px 6px;
margin: 1px;
}
@font-face {
src: url(weasyprint.otb);
font-family: weasyprint-otb;
}
body {
color: red;
font-family: weasyprint-otb;
font-size: 4px;
line-height: 1;
}
</style>
AaA''')
Binary file added tests/resources/weasyprint.otb
Binary file not shown.
6 changes: 3 additions & 3 deletions weasyprint/draw.py
Original file line number Diff line number Diff line change
Expand Up @@ -1079,7 +1079,7 @@ def draw_first_line(stream, textbox, text_overflow, block_ellipsis, x, y,
while runs[-1].next != ffi.NULL:
runs.append(runs[-1].next)

matrix = Matrix(font_size, 0, 0, -font_size, x, y)
matrix = Matrix(1, 0, 0, -1, x, y)
if angle:
matrix = Matrix(a=cos(angle), b=-sin(angle),
c=sin(angle), d=cos(angle)) @ matrix
Expand Down Expand Up @@ -1111,7 +1111,7 @@ def draw_first_line(stream, textbox, text_overflow, block_ellipsis, x, y,
stream.show_text(string)
string = ''
last_font = font
stream.set_font_size(font.hash, 1)
stream.set_font_size(font.hash, 1 if font.bitmap else font_size)
string += '<'
for i in range(num_glyphs):
glyph_info = glyphs[i]
Expand All @@ -1126,7 +1126,7 @@ def draw_first_line(stream, textbox, text_overflow, block_ellipsis, x, y,
offset = glyph_info.geometry.x_offset / font_size
if offset:
string += f'>{-offset}<'
string += f'{glyph:04x}'
string += f'{glyph:02x}' if font.bitmap else f'{glyph:04x}'

# Ink bounding box and logical widths in font
if glyph not in font.widths:
Expand Down
Loading

0 comments on commit d8533da

Please sign in to comment.