>>> from pagebot.fonttoolbox.objects.font import findFont >>> from pagebot.document import Document >>> from pagebot.constants import Letter, RIGHT >>> from pagebot import getContext >>> from pagebot.conditions import * >>> from pagebot.toolbox.color
(self, f, showLabel=True, labelSize=7, sampleText=None,
factor=0.9, location=None, useOpsz=True, **kwargs)
| 25 | SAMPLE = 'Jabberwocky' |
| 26 | |
| 27 | def __init__(self, f, showLabel=True, labelSize=7, sampleText=None, |
| 28 | factor=0.9, location=None, useOpsz=True, **kwargs): |
| 29 | """ |
| 30 | >>> from pagebot.fonttoolbox.objects.font import findFont |
| 31 | >>> from pagebot.document import Document |
| 32 | >>> from pagebot.constants import Letter, RIGHT |
| 33 | >>> from pagebot import getContext |
| 34 | >>> from pagebot.conditions import * |
| 35 | >>> from pagebot.toolbox.color import color |
| 36 | >>> c = getContext() |
| 37 | >>> w, h = Letter |
| 38 | >>> doc = Document(w=w, h=h, padding=80, autoPages=2, context=c) |
| 39 | >>> style = dict(fill=color(0.95), leading=em(1.3), fontSize=48, xTextAlign=RIGHT) |
| 40 | >>> conditions = [Fit()] # FIX: Does not seem to work for Text |
| 41 | >>> page = doc[1] |
| 42 | >>> font1 = findFont('AmstelvarAlpha-VF') |
| 43 | >>> loc = dict(wght=1) |
| 44 | >>> useOpsz = False |
| 45 | >>> page.pw, page.w, 500 |
| 46 | (6.28", 8.50", 500) |
| 47 | >>> gs = Waterfall(font1, parent=page, conditions=conditions, padding=20, style=style, w=page.pw, h=page.ph, location=loc, useOpsz=useOpsz, context=c) |
| 48 | >>> style = dict(stroke=0, strokeWidth=0.25, leading=em(1.3), fontSize=48, xTextAlign=RIGHT) |
| 49 | >>> page = doc[2] |
| 50 | >>> font2 = findFont('RobotoDelta-VF') |
| 51 | >>> #font2 = findFont('Upgrade-Regular') |
| 52 | >>> #font2 = findFont('Escrow-Bold') |
| 53 | >>> gs = Waterfall(font2, parent=page, conditions=conditions, style=style, w=page.pw, h=page.ph, padding=20, location=loc, useOpsz=useOpsz, context=c) |
| 54 | >>> #score = doc.solve() |
| 55 | >>> doc.export('_export/%sWaterfall_opsz_%s.pdf' % (font1.info.familyName, useOpsz)) |
| 56 | |
| 57 | TODO: Make self.css('xTextAlign') work for CENTER |
| 58 | """ |
| 59 | Text.__init__(self, **kwargs) |
| 60 | c = self.context |
| 61 | self.useOpsz = useOpsz # Only for the sample lines. Labels always have opsz. |
| 62 | self.f = f |
| 63 | if not location: |
| 64 | location = {} |
| 65 | self.factor = factor # Decreasing multiplication factor for fontSize |
| 66 | style = self.style.copy() |
| 67 | labelStyle = self.style.copy() |
| 68 | labelStyle['font'] = self.getInstance(f, dict(opsz=labelSize)).path |
| 69 | labelStyle['fontSize'] = labelSize |
| 70 | labelStyle['leading'] = em(1) |
| 71 | |
| 72 | w = self.pw # Initial with to fit top sample |
| 73 | location['opsz'] = None |
| 74 | style['font'] = self.getInstance(self.f, self.getLocation(self.f, location)).path |
| 75 | sampleText = sampleText or self.SAMPLE |
| 76 | matchingLine = c.newString(sampleText+'\n', style=style, w=w) |
| 77 | style['fontSize'] = fontSize = pt(int(matchingLine.fontSize / 8)) * 8 |
| 78 | |
| 79 | bs = c.newString('', style=style) |
| 80 | while fontSize >= 12: |
| 81 | # Still fitting? Otherwise stop the loop |
| 82 | # TODO: Measure both lines (label + samleText) for fitting. |
| 83 | tw, th = bs.textSize |
| 84 | if th > self.ph: |
nothing calls this directly
no test coverage detected