Coverage for src/rtflite/fonts_mapping.py: 100%

17 statements  

« prev     ^ index     » next       coverage.py v7.10.3, created at 2025-08-14 16:35 +0000

1from typing import Literal, Mapping 

2 

3FontName = Literal[ 

4 "Times New Roman", 

5 "Times New Roman Greek", 

6 "Arial Greek", 

7 "Arial", 

8 "Helvetica", 

9 "Calibri", 

10 "Georgia", 

11 "Cambria", 

12 "Courier New", 

13 "Symbol", 

14] 

15 

16FontNumber = Literal[1, 2, 3, 4, 5, 6, 7, 8, 9, 10] 

17 

18 

19class FontMapping: 

20 """Centralized font mapping for RTF document generation.""" 

21 

22 @staticmethod 

23 def get_font_table() -> Mapping: 

24 """Get complete font table with all properties.""" 

25 return { 

26 "type": list(range(1, 11)), 

27 "name": [ 

28 "Times New Roman", 

29 "Times New Roman Greek", 

30 "Arial Greek", 

31 "Arial", 

32 "Helvetica", 

33 "Calibri", 

34 "Georgia", 

35 "Cambria", 

36 "Courier New", 

37 "Symbol", 

38 ], 

39 "style": [ 

40 "\\froman", 

41 "\\froman", 

42 "\\fswiss", 

43 "\\fswiss", 

44 "\\fswiss", 

45 "\\fswiss", 

46 "\\froman", 

47 "\\ffroman", 

48 "\\fmodern", 

49 "\\ftech", 

50 ], 

51 "rtf_code": [f"\\f{i}" for i in range(10)], 

52 "family": [ 

53 "Times", 

54 "Times", 

55 "ArialMT", 

56 "ArialMT", 

57 "Helvetica", 

58 "Calibri", 

59 "Georgia", 

60 "Cambria", 

61 "Courier", 

62 "Times", 

63 ], 

64 "charset": [ 

65 "\\fcharset1", 

66 "\\fcharset161", 

67 "\\fcharset161", 

68 "\\fcharset0", 

69 "\\fcharset1", 

70 "\\fcharset1", 

71 "\\fcharset1", 

72 "\\fcharset1", 

73 "\\fcharset0", 

74 "\\fcharset2", 

75 ], 

76 } 

77 

78 @staticmethod 

79 def get_font_name_to_number_mapping() -> dict[FontName, int]: 

80 """Get mapping from font names to font numbers.""" 

81 return { 

82 "Times New Roman": 1, 

83 "Times New Roman Greek": 2, 

84 "Arial Greek": 3, 

85 "Arial": 4, 

86 "Helvetica": 5, 

87 "Calibri": 6, 

88 "Georgia": 7, 

89 "Cambria": 8, 

90 "Courier New": 9, 

91 "Symbol": 10, 

92 } 

93 

94 @staticmethod 

95 def get_font_number_to_name_mapping() -> dict[int, FontName]: 

96 """Get mapping from font numbers to font names.""" 

97 name_to_number = FontMapping.get_font_name_to_number_mapping() 

98 return {v: k for k, v in name_to_number.items()} 

99 

100 @staticmethod 

101 def get_font_paths() -> dict[FontName, str]: 

102 """Get mapping from font names to font file paths.""" 

103 return { 

104 "Times New Roman": "liberation/LiberationSerif-Regular.ttf", 

105 "Times New Roman Greek": "liberation/LiberationSerif-Regular.ttf", 

106 "Arial Greek": "liberation/LiberationSans-Regular.ttf", 

107 "Arial": "liberation/LiberationSans-Regular.ttf", 

108 "Helvetica": "liberation/LiberationSans-Regular.ttf", 

109 "Calibri": "cros/Carlito-Regular.ttf", 

110 "Georgia": "cros/Gelasio-Regular.ttf", 

111 "Cambria": "cros/Caladea-Regular.ttf", 

112 "Courier New": "liberation/LiberationMono-Regular.ttf", 

113 "Symbol": "liberation/LiberationSerif-Regular.ttf", 

114 }