@@ -317,26 +317,9 @@ def charname(char):
317317c = font .createMappedChar (32 )
318318c .width = 256
319319
320- # recommended by OpenType specification
321- c = font .createChar (- 1 , '.notdef' )
322- c .addReference ('question' , psMat .compose (psMat .scale (0.5 ), psMat .translate (font .ascent * 0.25 , font .ascent * 0.25 )))
323- c .unlinkRef ()
324- c .width = round (font .em * 0.6 )
325- pen = c .glyphPen (replace = False )
326- pen .moveTo (20 , 20 )
327- pen .lineTo ((c .width - 20 , 20 ))
328- pen .lineTo ((c .width - 20 , font .ascent - 20 ))
329- pen .lineTo ((20 , font .ascent - 20 ))
330- pen .lineTo ((20 , 20 ))
331- pen .lineTo ((60 , 60 ))
332- pen .lineTo ((60 , font .ascent - 60 ))
333- pen .lineTo ((c .width - 60 , font .ascent - 60 ))
334- pen .lineTo ((c .width - 60 , 60 ))
335- pen .lineTo ((60 , 60 ))
336- pen .closePath ()
337- c = font .createChar (0x0000 , '.null' )
320+ c = font .createChar (0x0000 , '.null' ) # U+0000: null, zero-width; required by OpenType
338321c .width = 256
339- c = font .createChar (0x000D , 'nonmarkingreturn' )
322+ c = font .createChar (0x000D , 'nonmarkingreturn' ) # U+000D: carriage return, zero-width; required by OpenType
340323c .width = 256
341324
342325
@@ -413,6 +396,23 @@ def _import_comic_glyph(font, name, svg_path, target_top, weight_delta=0):
413396 return g
414397
415398
399+ # .notdef is shown for any codepoint the font doesn't cover; OpenType requires it.
400+ # Hand-drawn source: xkcd #1913 (I), a sketchy question-mark-in-a-box.
401+ _notdef_svg = os .path .join (_COMIC_CHARS_DIR , 'notdef.svg' )
402+ _notdef_src = _import_comic_glyph (font , 'notdef' , _notdef_svg , target_top = font .ascent , weight_delta = 20 )
403+ _bb = _notdef_src .boundingBox ()
404+ _notdef_src .transform (psMat .translate (0 , - _bb [1 ]))
405+ _bb = _notdef_src .boundingBox ()
406+ if _bb [3 ] > 0 :
407+ _notdef_src .transform (psMat .scale (font .ascent / _bb [3 ]))
408+ _notdef_src .width = int (round (_notdef_src .boundingBox ()[2 ] + 20 ))
409+ c = font .createChar (- 1 , '.notdef' )
410+ c .clear ()
411+ for _cont in _notdef_src .foreground :
412+ c .foreground += _cont
413+ c .width = _notdef_src .width
414+
415+
416416# Greek letters vectorised by pt4 from xkcd comic images.
417417# Each entry: (svg_name, unicode_cp, ref_char_for_height, baseline_snap)
418418# baseline_snap=True → translate so bb[1]=0 (letters that sit on the baseline).
@@ -614,6 +614,23 @@ def _import_comic_glyph(font, name, svg_path, target_top, weight_delta=0):
614614 _ch .width = _g .width
615615
616616
617+ # □ U+25A1 WHITE SQUARE — hand-drawn source from extras/square.png.
618+ _square_svg = os .path .join (_COMIC_CHARS_DIR , 'square.svg' )
619+ _target_top_sq = font ['H' ].boundingBox ()[3 ]
620+ _square_src = _import_comic_glyph (font , 'square' , _square_svg , target_top = _target_top_sq , weight_delta = 45 )
621+ _bb = _square_src .boundingBox ()
622+ _square_src .transform (psMat .translate (0 , - _bb [1 ]))
623+ _bb = _square_src .boundingBox ()
624+ if _bb [3 ] > 0 :
625+ _square_src .transform (psMat .scale (_target_top_sq / _bb [3 ]))
626+ _square_src .width = int (round (_square_src .boundingBox ()[2 ] + 20 ))
627+ _ch = font .createMappedChar (0x25A1 )
628+ _ch .clear ()
629+ for _cont in _square_src .foreground :
630+ _ch .foreground += _cont
631+ _ch .width = _square_src .width
632+
633+
617634# ---------------------------------------------------------------------------
618635# Save
619636# ---------------------------------------------------------------------------
0 commit comments