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

18 statements  

« prev     ^ index     » next       coverage.py v7.12.0, created at 2025-11-28 05:09 +0000

1from collections.abc import Mapping 

2from typing import Literal 

3 

4FontName = Literal[ 

5 "Times New Roman", 

6 "Times New Roman Greek", 

7 "Arial Greek", 

8 "Arial", 

9 "Helvetica", 

10 "Calibri", 

11 "Georgia", 

12 "Cambria", 

13 "Courier New", 

14 "Symbol", 

15] 

16 

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

18 

19 

20class FontMapping: 

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

22 

23 @staticmethod 

24 def get_font_table() -> Mapping: 

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

26 return { 

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

28 "name": [ 

29 "Times New Roman", 

30 "Times New Roman Greek", 

31 "Arial Greek", 

32 "Arial", 

33 "Helvetica", 

34 "Calibri", 

35 "Georgia", 

36 "Cambria", 

37 "Courier New", 

38 "Symbol", 

39 ], 

40 "style": [ 

41 "\\froman", 

42 "\\froman", 

43 "\\fswiss", 

44 "\\fswiss", 

45 "\\fswiss", 

46 "\\fswiss", 

47 "\\froman", 

48 "\\ffroman", 

49 "\\fmodern", 

50 "\\ftech", 

51 ], 

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

53 "family": [ 

54 "Times", 

55 "Times", 

56 "ArialMT", 

57 "ArialMT", 

58 "Helvetica", 

59 "Calibri", 

60 "Georgia", 

61 "Cambria", 

62 "Courier", 

63 "Times", 

64 ], 

65 "charset": [ 

66 "\\fcharset1", 

67 "\\fcharset161", 

68 "\\fcharset161", 

69 "\\fcharset0", 

70 "\\fcharset1", 

71 "\\fcharset1", 

72 "\\fcharset1", 

73 "\\fcharset1", 

74 "\\fcharset0", 

75 "\\fcharset2", 

76 ], 

77 } 

78 

79 @staticmethod 

80 def get_font_name_to_number_mapping() -> Mapping[FontName, int]: 

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

82 return { 

83 "Times New Roman": 1, 

84 "Times New Roman Greek": 2, 

85 "Arial Greek": 3, 

86 "Arial": 4, 

87 "Helvetica": 5, 

88 "Calibri": 6, 

89 "Georgia": 7, 

90 "Cambria": 8, 

91 "Courier New": 9, 

92 "Symbol": 10, 

93 } 

94 

95 @staticmethod 

96 def get_font_number_to_name_mapping() -> Mapping[int, FontName]: 

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

98 name_to_number = FontMapping.get_font_name_to_number_mapping() 

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

100 

101 @staticmethod 

102 def get_font_paths() -> Mapping[FontName, str]: 

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

104 return { 

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

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

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

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

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

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

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

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

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

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

115 }