MCPcopy Create free account
hub / github.com/PageBot/PageBot / getFSStyle

Method getFSStyle

Lib/pagebot/contexts/basecontext/babelrun.py:83–163  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

81 return findFont(fontName)
82
83 def getFSStyle(self):
84 # D E P R E C A T E D
85 # FIXME - Petr The question is if we need to convert to FlatString at all.
86 # Can't we just use the main data in Babelstring, until processing into
87 # lines or text?
88
89 # Instead of using e.g. bs.tracking, we need to process the styles
90 # of all runs, not just the last one.
91 style = self.style
92
93 # DrawBot-OSX, setting the hyphenation is global, before a
94 # FormattedString is created.
95 hyphenation = style.get('hyphenation', False)
96
97 # In case an error occurs in these parameters, DrawBot ignores all.
98 # upt(fontSize), upt(leading, base=fontSize),
99 # textColor.rgba, align)
100
101 # Create the style for this text run.
102 font = self.getFont()
103
104 if font is None:
105 fontPath = DEFAULT_FONT
106 else:
107 fontPath = font.path
108 fontSize = style.get('fontSize', DEFAULT_FONT_SIZE)
109 leading = style.get('leading', em(1, base=fontSize)) # Vertical space adding to fontSize.
110
111 fsStyle = dict(
112 font=fontPath,
113 fontSize=upt(fontSize),
114 lineHeight=upt(leading, base=fontSize),
115 align=style.get('xTextAlign') or style.get('xAlign', LEFT),
116 tracking=upt(style.get('tracking', 0), base=fontSize),
117 strokeWidth=upt(style.get('strokeWidth')),
118 baselineShift=upt(style.get('baselineShift'), base=fontSize),
119 language=style.get('language', DEFAULT_LANGUAGE),
120 indent=upt(style.get('indent', 0), base=fontSize),
121 tailIndent=-abs(upt(style.get('tailIndent', 0), base=fontSize)), # DrawBot wants negative number)
122 firstLineIndent=upt(style.get('firstLineIndent', 0), base=fontSize),
123 underline={True:'single', False:None}.get(style.get('underline', False)),
124 # Increasing value moves text up, decreasing the leading.
125 paragraphTopSpacing=upt(style.get('paragraphTopSpacing', 0), base=fontSize),
126 paragraphBottomSpacing=upt(style.get('paragraphBottomSpacing', 0), base=fontSize),
127 )
128
129 if 'textFill' in style:
130 textFill = style['textFill']
131 if textFill is not None:
132 textFill = color(textFill)
133 if textFill.isCmyk:
134 fsStyle['cmykFill'] = textFill.cmyk
135 else:
136 fsStyle['fill'] = textFill.rgba
137
138 if 'textStroke' in style:
139 textStroke = style['textStroke']
140 if textStroke is not None:

Callers

nothing calls this directly

Calls 6

getFontMethod · 0.95
emFunction · 0.90
uptFunction · 0.90
colorFunction · 0.90
getMethod · 0.45
appendMethod · 0.45

Tested by

no test coverage detected