Skip to content

Commit 5045fbc

Browse files
committed
Lots of minor changes
1 parent 8b8c913 commit 5045fbc

23 files changed

+269
-82
lines changed

docstrings/glyph.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,7 @@
9191
9292
Computing the control box is very fast, while getting the bounding box
9393
can take much more time as it needs to walk over all segments and arcs
94-
in the outline. To get the latter, you can use the ‘ftbbox’ component
95-
which is dedicated to this single task (TODO).
94+
in the outline.
9695
9796
Parameters
9897
----------

docstrings/outline.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -117,13 +117,18 @@
117117
be called.
118118
119119
shift : int, optional
120-
The shift that is applied to coordinates before they are sent to
120+
The number of bits to shift coordinates before they are sent to
121121
the emitter.
122122
123123
delta : int, optional
124124
The delta that is applied to coordinates before they are sent to
125125
the emitter, but after the shift.
126126
127+
The transformation applied by shift and delta is::
128+
129+
x' = (x << shift) - delta
130+
y' = (y << shift) - delta
131+
127132
Examples
128133
--------
129134

docstrings/tt_header.py

-8
Original file line numberDiff line numberDiff line change
@@ -157,11 +157,3 @@
157157
158158
- -2: Like -1, but also contains neutrals
159159
"""
160-
161-
TT_Header_index_to_loc_format = """
162-
TODO
163-
"""
164-
165-
TT_Header_glyph_data_format = """
166-
TODO
167-
"""

docstrings/tt_os2.py

+142-11
Original file line numberDiff line numberDiff line change
@@ -347,41 +347,172 @@ class (either by a font designer or by some automated means) the
347347
"""
348348

349349
TT_OS2_typo_ascender = """
350-
TODO
350+
The typographic ascender for this font. Remember that this is not the
351+
same as `TT_HoriHeader.ascender`, which Apple defines in a far
352+
different manner.
353+
354+
The suggested usage for `typo_ascender` is that it be used in
355+
conjunction with `TT_Header.units_per_em` to compute a typographically
356+
correct default line spacing. The goal is to free applications from
357+
Macintosh or Windows-specific metrics which are constrained by
358+
backward compatibility requirements. These new metrics, when combined
359+
with the character design widths, will allow applications to lay out
360+
documents in a typographically correct and portable fashion.
361+
362+
For CJK (Chinese, Japanese, and Korean) fonts that are intended to be
363+
used for vertical writing (in addition to horizontal writing), the
364+
required value for `typo_ascender` is that which describes the top of
365+
the of the ideographic em-box. For example, if the ideographic em-box
366+
of the font extends from coordinates 0,-120 to 1000,880 (that is, a
367+
1000x1000 box set 120 design units below the Latin baseline), then the
368+
value of `typo_ascender` must be set to 880. Failing to adhere to these
369+
requirements will result in incorrect vertical layout.
351370
"""
352371

353372
TT_OS2_typo_descender = """
354-
TODO
373+
The typographic descender for this font. Remember that this is not the
374+
same as the `TT_HoriHeader.descender`, which Apple defines in a far
375+
different manner.
376+
377+
The suggested usage for `typo_descender` is that it be used in
378+
conjunction with `TT_Header.units_per_em` to compute a typographically
379+
correct default line spacing. The goal is to free applications from
380+
Macintosh or Windows-specific metrics which are constrained by
381+
backward compatability requirements. These new metrics, when combined
382+
with the character design widths, will allow applications to lay out
383+
documents in a typographically correct and portable fashion.
384+
385+
For CJK (Chinese, Japanese, and Korean) fonts that are intended to be
386+
used for vertical writing (in addition to horizontal writing), the
387+
required value for `typo_descender` is that which describes the bottom
388+
of the of the ideographic em-box. For example, if the ideographic
389+
em-box of the font extends from coordinates 0,-120 to 1000,880 (that
390+
is, a 1000x1000 box set 120 design units below the Latin baseline),
391+
then the value of `typo_descender` must be set to -120. Failing to
392+
adhere to these requirements will result in incorrect vertical layout.
355393
"""
356394

357395
TT_OS2_typo_line_gap = """
358-
TODO
359-
"""
396+
The typographic line gap for this font. Remember that this is not the
397+
same as `TT_HoriHeader.line_gap`, which Apple defines in a far
398+
different manner.
399+
400+
The suggested usage for `typo_line_gap` is that it be used in
401+
conjunction with `TTHeader.units_per_em` to compute a typographically
402+
correct default line spacing. Typical values average 7-10% of units
403+
per em. The goal is to free applications from Macintosh or
404+
Windows-specific metrics which are constrained by backward
405+
compatability requirements. These new metrics, when combined with the
406+
character design widths, will allow applications to lay out documents
407+
in a typographically correct and portable fashion. """
360408

361409
TT_OS2_win_ascent = """
362-
TODO
410+
The ascender metric for Windows. This, too, is distinct from Apple's
411+
`TT_HoriHeader.ascender` value and from the `typo_ascender`
412+
values. `win_ascent` is computed as the ``y_max`` for all characters
413+
in the Windows ANSI character set. `win_ascent` is used to compute the
414+
Windows font height and default line spacing. For platform 3 encoding
415+
0 fonts, it is the same as `TT_Header.y_max`. Windows will clip the
416+
bitmap of any portion of a glyph that appears above this value. Some
417+
applications use this value to determine default line spacing. This is
418+
strongly discouraged. The typographic ascender, descender and line gap
419+
fields in conjunction with `TT_Header.units_per_em` should be used for
420+
this purpose. Developers should set this field keeping the above
421+
factors in mind.
422+
423+
If any clipping is unacceptable, then the value should be set to
424+
`TT_Header.y_max`.
425+
426+
However, if a developer desires to provide appropriate default line
427+
spacing using this field, for those applications that continue to use
428+
this field for doing so (against OpenType recommendations), then the
429+
value should be set appropriately. In such a case, it may result in
430+
some glyph bitmaps being clipped.
363431
"""
364432

365433
TT_OS2_win_descent = """
366-
TODO
434+
The descender metric for Windows. This, too, is distinct from Apple's
435+
`TT_HoriHeader.descender` value and from the
436+
`typo_descender`. `win_descent` is computed as the ``-y_min`` for all
437+
characters in the Windows ANSI character set. `win_descent` is used to
438+
compute the Windows font height and default line spacing. For platform
439+
3 encoding 0 fonts, it is the same as ``-TTHeader.y_min``. Windows
440+
will clip the bitmap of any portion of a glyph that appears below this
441+
value. Some applications use this value to determine default line
442+
spacing. This is strongly discouraged. The typographic ascender,
443+
descender and line gap fields in conjunction with unitsPerEm should be
444+
used for this purpose. Developers should set this field keeping the
445+
above factors in mind.
446+
447+
If any clipping is unacceptable, then the value should be set to
448+
`TT_Header.y_min`.
449+
450+
However, if a developer desires to provide appropriate default line
451+
spacing using this field, for those applications that continue to use
452+
this field for doing so (against OpenType recommendations), then the
453+
value should be set appropriately. In such a case, it may result in
454+
some glyph bitmaps being clipped.
367455
"""
368456

369457
TT_OS2_x_height = """
370-
TODO
458+
This metric specifies the distance between the baseline and the
459+
approximate height of non-ascending lowercase letters measured in font
460+
units. This value would normally be specified by a type designer but
461+
in situations where that is not possible, for example when a legacy
462+
font is being converted, the value may be set equal to the top of the
463+
unscaled and unhinted glyph bounding box of the glyph encoded at
464+
``U+0078`` (``LATIN SMALL LETTER X``). If no glyph is encoded in this
465+
position the field should be set to 0.
466+
467+
This metric, if specified, can be used in font substitution: the
468+
`x_height` value of one font can be scaled to approximate the apparent
469+
size of another.
371470
"""
372471

373472
TT_OS2_cap_height = """
374-
TODO
473+
This metric specifies the distance between the baseline and the
474+
approximate height of uppercase letters measured in font units. This
475+
value would normally be specified by a type designer but in situations
476+
where that is not possible, for example when a legacy font is being
477+
converted, the value may be set equal to the top of the unscaled and
478+
unhinted glyph bounding box of the glyph encoded at ``U+0048`` (``LATIN
479+
CAPITAL LETTER H``). If no glyph is encoded in this position the field
480+
should be set to 0.
481+
482+
This metric, if specified, can be used in systems that specify type
483+
size by capital height measured in millimeters. It can also be used as
484+
an alignment metric; the top of a drop capital, for instance, can be
485+
aligned to the `cap_height` metric of the first line of text.
375486
"""
376487

377488
TT_OS2_default_char = """
378-
TODO
489+
Whenever a request is made for a character that is not in the font,
490+
Windows provides this default character. If the value of this field is
491+
zero, glyph ID 0 is to be used for the default character otherwise
492+
this is the Unicode encoding of the glyph that Windows uses as the
493+
default character. This field cannot represent supplementary character
494+
values (codepoints greater than ``0xFFFF``), and so applications are
495+
strongly discouraged from using this field.
379496
"""
380497

381498
TT_OS2_break_char = """
382-
TODO
499+
This is the Unicode encoding of the glyph that Windows uses as the
500+
break character. The break character is used to separate words and
501+
justify text. Most fonts specify 'space' as the break character. This
502+
field cannot represent supplementary character values (codepoints
503+
greater than ``0xFFFF``), and so applications are strongly discouraged
504+
from using this field.
383505
"""
384506

385507
TT_OS2_max_context = """
386-
TODO
508+
The maximum length of a target glyph context for any feature in this
509+
font. For example, a font which has only a pair kerning feature should
510+
set this field to 2. If the font also has a ligature feature in which
511+
the glyph sequence "f f i" is substituted by the ligature "ffi", then
512+
this field should be set to 3. This field could be useful to
513+
sophisticated line-breaking engines in determining how far they should
514+
look ahead to test whether something could change that effects the
515+
line breaking. For chaining contextual lookups, the length of the
516+
string (covered glyph) + (input sequence) + (lookahead sequence)
517+
should be considered.
387518
"""

lib/freetypy/tests/test_face.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -113,12 +113,13 @@ def test_face_set_transform():
113113

114114

115115
def test_kerning():
116-
# TODO: Why are we not getting a kerning value here?
117116
face = ft.Face(vera_path())
117+
face.set_char_size(24, 24, 300, 300)
118118
assert face.face_flags & ft.FACE_FLAG.KERNING
119119
A = face.get_char_index(ord('A'))
120120
V = face.get_char_index(ord('V'))
121-
assert face.get_kerning(A, V) == (0, 0)
121+
assert face.get_kerning(A, V, ft.KERNING.UNSCALED) == (-2.046875, 0.0)
122+
assert face.get_kerning(A, V, ft.KERNING.DEFAULT) == (-6, 0)
122123

123124

124125
def test_get_glyph_name():

lib/freetypy/tests/test_layout.py

+11-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535

3636
def test_layout():
3737
face = ft.Face(vera_path())
38-
face.set_charmap(0)
38+
face.select_charmap(ft.ENCODING.UNICODE)
3939
face.set_char_size(24.0)
4040

4141
layout = ft.Layout(
@@ -51,3 +51,13 @@ def test_layout():
5151
55, 75, 72, 3, 84, 88, 76, 70, 78, 3, 69, 85, 82, 90, 81, 3,
5252
73, 82, 91, 3, 77, 88, 80, 83, 72, 71, 3, 82, 89, 72, 85, 3,
5353
87, 75, 72, 3, 79, 68, 93, 92, 3, 71, 82, 74]
54+
55+
56+
@raises(ValueError)
57+
def test_layout_wrong_encoding():
58+
face = ft.Face(vera_path())
59+
face.set_charmap(0)
60+
face.set_char_size(24.0)
61+
62+
layout = ft.Layout(
63+
face, "The quick brown fox jumped over the lazy dog")

lib/freetypy/tests/test_truetype.py

-2
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,6 @@ def test_tt_header():
4848
assert x.flags == 31
4949
assert x.font_direction == 1
5050
assert x.font_revision == 2.0
51-
assert x.glyph_data_format == 0
52-
assert x.index_to_loc_format == 0
5351
assert x.lowest_rec_ppem == 8
5452
assert x.mac_style == 0
5553
assert x.magic_number == 0x5f0f3cf5

lib/freetypy/tests/util.py

-3
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,6 @@
3333

3434
from __future__ import print_function, unicode_literals, absolute_import
3535

36-
import functools
37-
import os
38-
3936

4037
from nose.tools import raises
4138

lib/freetypy/util.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
import sys
3939

4040

41-
__all__ = ['vera_path', 'draw_glyph_to_console']
41+
__all__ = ['vera_path', 'bitmap_to_ascii']
4242

4343

4444
def vera_path():
@@ -49,7 +49,7 @@ def vera_path():
4949
return os.path.join(os.path.dirname(__file__), 'data', 'Vera.ttf')
5050

5151

52-
def glyph_to_ascii(a):
52+
def bitmap_to_ascii(a):
5353
"""
5454
Converts a single glyph to a string with an ASCII drawing of that
5555
glyph.

setup.py

-4
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,10 @@
3131
# as representing official policies, either expressed or implied, of
3232
# the FreeBSD Project.
3333

34-
# TODO: PEP8-ify identifiers
35-
3634
from __future__ import print_function, absolute_import
3735

3836
from distutils.core import setup, Extension
3937
import glob
40-
import os
41-
import subprocess
4238
import sys
4339

4440
sys.path.insert(0, 'buildext')

src/charmap.c

+24-2
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,6 @@ either expressed or implied, of the FreeBSD Project.
3535
#include FT_TRUETYPE_TABLES_H
3636
#include FT_TRUETYPE_IDS_H
3737

38-
/* TODO: Add a nice repr here */
39-
4038

4139
#define CHARMAP_GETTER(name, type) GETTER(name, type, FT_CharMapRec, Py_CharMap);
4240
#define CHARMAP_METHOD(name) DEF_METHOD(name, CharMap)
@@ -217,6 +215,29 @@ static PyMethodDef Py_CharMap_methods[] = {
217215
};
218216

219217

218+
/****************************************************************************
219+
repr
220+
*/
221+
222+
223+
static PyObject *
224+
Py_CharMap_repr(Py_CharMap *self)
225+
{
226+
PyObject *encoding;
227+
PyObject *repr;
228+
229+
encoding = encoding_get(self, NULL);
230+
if (encoding == NULL) {
231+
return NULL;
232+
}
233+
234+
repr = PyUnicode_FromFormat("<freetypy.CharMap '%s'>", encoding);
235+
236+
Py_DECREF(encoding);
237+
return repr;
238+
}
239+
240+
220241
/****************************************************************************
221242
Setup
222243
*/
@@ -252,6 +273,7 @@ int setup_CharMap(PyObject *m)
252273
.tp_name = "freetypy.CharMap",
253274
.tp_basicsize = sizeof(Py_CharMap),
254275
.tp_doc = doc_CharMap__init__,
276+
.tp_repr = (unaryfunc)Py_CharMap_repr,
255277
.tp_getset = Py_CharMap_getset,
256278
.tp_methods = Py_CharMap_methods,
257279
.tp_init = (initproc)Py_CharMap_init,

0 commit comments

Comments
 (0)