|
18 | 18 | from fontTools.pens.reverseContourPen import ReverseContourPen
|
19 | 19 | from fontTools.pens.transformPen import TransformPen
|
20 | 20 |
|
| 21 | +# we keep this unused import in case some external code relied on the |
| 22 | +# old location of this function, which now lives in fontTools |
| 23 | +from fontTools.ttLib.tables.O_S_2f_2 import calcCodePageRanges # noqa: F401 |
| 24 | + |
21 | 25 | from ufo2ft.constants import OPENTYPE_CATEGORIES_KEY, UNICODE_SCRIPT_ALIASES
|
22 | 26 | from ufo2ft.errors import InvalidDesignSpaceData, InvalidFontData
|
23 | 27 | from ufo2ft.fontInfoData import getAttrWithFallback
|
@@ -373,101 +377,6 @@ def unicodeScriptDirection(uv):
|
373 | 377 | return unicodedata.script_horizontal_direction(sc, "LTR")
|
374 | 378 |
|
375 | 379 |
|
376 |
| -def calcCodePageRanges(unicodes): |
377 |
| - """Given a set of Unicode codepoints (integers), calculate the |
378 |
| - corresponding OS/2 CodePage range bits. |
379 |
| - This is a direct translation of FontForge implementation: |
380 |
| - https://github.com/fontforge/fontforge/blob/7b2c074/fontforge/tottf.c#L3158 |
381 |
| - """ |
382 |
| - codepageRanges = set() |
383 |
| - |
384 |
| - chars = [chr(u) for u in unicodes] |
385 |
| - |
386 |
| - hasAscii = set(range(0x20, 0x7E)).issubset(unicodes) |
387 |
| - hasLineart = "┤" in chars |
388 |
| - |
389 |
| - for char in chars: |
390 |
| - if char == "Þ" and hasAscii: |
391 |
| - codepageRanges.add(0) # Latin 1 |
392 |
| - elif char == "Ľ" and hasAscii: |
393 |
| - codepageRanges.add(1) # Latin 2: Eastern Europe |
394 |
| - if hasLineart: |
395 |
| - codepageRanges.add(58) # Latin 2 |
396 |
| - elif char == "Б": |
397 |
| - codepageRanges.add(2) # Cyrillic |
398 |
| - if "Ѕ" in chars and hasLineart: |
399 |
| - codepageRanges.add(57) # IBM Cyrillic |
400 |
| - if "╜" in chars and hasLineart: |
401 |
| - codepageRanges.add(49) # MS-DOS Russian |
402 |
| - elif char == "Ά": |
403 |
| - codepageRanges.add(3) # Greek |
404 |
| - if hasLineart and "½" in chars: |
405 |
| - codepageRanges.add(48) # IBM Greek |
406 |
| - if hasLineart and "√" in chars: |
407 |
| - codepageRanges.add(60) # Greek, former 437 G |
408 |
| - elif char == "İ" and hasAscii: |
409 |
| - codepageRanges.add(4) # Turkish |
410 |
| - if hasLineart: |
411 |
| - codepageRanges.add(56) # IBM turkish |
412 |
| - elif char == "א": |
413 |
| - codepageRanges.add(5) # Hebrew |
414 |
| - if hasLineart and "√" in chars: |
415 |
| - codepageRanges.add(53) # Hebrew |
416 |
| - elif char == "ر": |
417 |
| - codepageRanges.add(6) # Arabic |
418 |
| - if "√" in chars: |
419 |
| - codepageRanges.add(51) # Arabic |
420 |
| - if hasLineart: |
421 |
| - codepageRanges.add(61) # Arabic; ASMO 708 |
422 |
| - elif char == "ŗ" and hasAscii: |
423 |
| - codepageRanges.add(7) # Windows Baltic |
424 |
| - if hasLineart: |
425 |
| - codepageRanges.add(59) # MS-DOS Baltic |
426 |
| - elif char == "₫" and hasAscii: |
427 |
| - codepageRanges.add(8) # Vietnamese |
428 |
| - elif char == "ๅ": |
429 |
| - codepageRanges.add(16) # Thai |
430 |
| - elif char == "エ": |
431 |
| - codepageRanges.add(17) # JIS/Japan |
432 |
| - elif char == "ㄅ": |
433 |
| - codepageRanges.add(18) # Chinese: Simplified chars |
434 |
| - elif char == "ㄱ": |
435 |
| - codepageRanges.add(19) # Korean wansung |
436 |
| - elif char == "央": |
437 |
| - codepageRanges.add(20) # Chinese: Traditional chars |
438 |
| - elif char == "곴": |
439 |
| - codepageRanges.add(21) # Korean Johab |
440 |
| - elif char == "♥" and hasAscii: |
441 |
| - codepageRanges.add(30) # OEM Character Set |
442 |
| - # TODO: Symbol bit has a special meaning (check the spec), we need |
443 |
| - # to confirm if this is wanted by default. |
444 |
| - # elif chr(0xF000) <= char <= chr(0xF0FF): |
445 |
| - # codepageRanges.add(31) # Symbol Character Set |
446 |
| - elif char == "þ" and hasAscii and hasLineart: |
447 |
| - codepageRanges.add(54) # MS-DOS Icelandic |
448 |
| - elif char == "╚" and hasAscii: |
449 |
| - codepageRanges.add(62) # WE/Latin 1 |
450 |
| - codepageRanges.add(63) # US |
451 |
| - elif hasAscii and hasLineart and "√" in chars: |
452 |
| - if char == "Å": |
453 |
| - codepageRanges.add(50) # MS-DOS Nordic |
454 |
| - elif char == "é": |
455 |
| - codepageRanges.add(52) # MS-DOS Canadian French |
456 |
| - elif char == "õ": |
457 |
| - codepageRanges.add(55) # MS-DOS Portuguese |
458 |
| - |
459 |
| - if hasAscii and "‰" in chars and "∑" in chars: |
460 |
| - codepageRanges.add(29) # Macintosh Character Set (US Roman) |
461 |
| - |
462 |
| - # when no codepage ranges can be enabled, fall back to enabling bit 0 |
463 |
| - # (Latin 1) so that the font works in MS Word: |
464 |
| - # https://github.com/googlei18n/fontmake/issues/468 |
465 |
| - if not codepageRanges: |
466 |
| - codepageRanges.add(0) |
467 |
| - |
468 |
| - return codepageRanges |
469 |
| - |
470 |
| - |
471 | 380 | class _LazyFontName:
|
472 | 381 | def __init__(self, font):
|
473 | 382 | self.font = font
|
|
0 commit comments