New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[question] position of first baseline? #105
Comments
This may or may not be related with #52 |
I stumbled upon
|
On May 23, 2017, at 5:20 PM, Frank Grießhammer ***@***.*** ***@***.***>> wrote:
In a text box, how does DrawBot specify the position of the first baseline for a given font?
I am currently working on a script that layers different fonts, and need to calculate the baseline offset – unfortunately that’s trickier than expected.
A common assumption is just subtracting the hhea.ascent value from the top of the text frame, but it’s not that simple – especially in fonts where hhea.ascent + |hhea.descent| != 1000.
Here is my test data (for simplicity’s sake, font size = UPM = 1000):
# SourceSansPro-Bold
# head.yMax: 1009
# hhea.ascent: 984
# hhea.descent: -273
# hhea.lineGap: 0
# baseline is 855 below top of text frame
# SourceSerifPro-Light
# head.yMax: 976
# hhea.ascent: 1036
# hhea.descent: -335
# hhea.lineGap: 0
# baseline is 850 below top of text frame
# MyriadPro-Light
# head.yMax: 935
# hhea.ascent: 750
# hhea.descent: -250
# hhea.lineGap: 200
# baseline is 750 below top of text frame
This may have been solved by @petrvanblokland <https://github.com/petrvanblokland> – I assume pageBot can deal with baselines?
Yes, PageBot has all parts (letters, lines, patterns, markers) inside a FormattedString accessible (position, style parameters and letters as paths).
Basically is also accessible in DrawBot – as Frederik made the samples –, but needs more NS code to find out.
Here is one of his samples.
… —
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub <#105>, or mute the thread <https://github.com/notifications/unsubscribe-auth/AAXBwSkWfDRSc_yUNGnEJXzF3Hm65UP7ks5r802UgaJpZM4NkTNQ>.
-----------------------------------------------
Petr van Blokland | twitter+skype @petrvanblokland
Intentionally not on FaceBook.
buro@petr.com <mailto:buro@petr.com> | www.petr.com <http://www.petr.com/>
mobile +31 6 24 219 502 | buro +31 15 887 1233
-----------------------------------------------
typetr.typenetwork.com <http://typetr.typenetwork.com/>
-----------------------------------------------
Rietveld 56 2611 LM Delft The Netherlands
-----------------------------------------------
Claudia Mens | claudia@petr.com <mailto:claudia@petr.com>
mobile +31 6 41 367 689 | buro +31 15 887 1233
-----------------------------------------------
|
Thanks Petr – the sample was filtered out (by Github I assume), but maybe you can email it privately? (or post here?) |
Here it is. |
Unfortunately that trick only works for a very small subset of fonts, Times among them.
|
For more detailed info, I open the font in fonttools.
All standard in PageBot. You'd like sneak preview git access?
… On May 23, 2017, at 8:54 PM, Frank Grießhammer ***@***.***> wrote:
Unfortunately that trick only works for a very small subset of fonts, Times among them.
import random as rnd
height = width = 1000
t = "hello world "
font_names = ['Times']
font_names.extend(rnd.sample(installedFonts(), 9))
for font_name in font_names:
newPage(width, height)
point_size = 100
line_height = point_size * 1.2
y_value = 500
fs_font_name_label = FormattedString(
font_name,
font=font_name,
fontSize=point_size/2,
lineHeight=line_height
)
fs_single = FormattedString(
t,
font=font_name,
fontSize=point_size,
lineHeight=line_height
)
font(font_name)
fontSize(point_size)
lineHeight(line_height)
print font_name
print fs_single.fontLineHeight()
print fs_single.fontDescender()
print
text(fs_single, (0, y_value))
r = (100, 0, 1000, y_value + fontLineHeight() + fontDescender())
label_rect = (100, height-200, width-200, 200)
fs_multiline = FormattedString(
t * 10,
font=font_name,
fontSize=point_size)
textBox(fs_font_name_label, label_rect)
textBox(fs_multiline, r)
strokeWidth(.2)
stroke(0, 0 ,1)
line((0, y_value), (1000, y_value))
stroke(1, 0, 0)
fill(None)
rect(*r)
baseline.pdf <https://github.com/typemytype/drawbot/files/1024128/baseline.pdf>
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub <#105 (comment)>, or mute the thread <https://github.com/notifications/unsubscribe-auth/AAXBwV4t1AzK8ZpcZgKA6P8DCOAOz7pDks5r83_YgaJpZM4NkTNQ>.
-----------------------------------------------
Petr van Blokland | twitter+skype @petrvanblokland
Intentionally not on FaceBook.
buro@petr.com | www.petr.com
mobile +31 6 24 219 502 | buro +31 15 887 1233
-----------------------------------------------
typetr.typenetwork.com
-----------------------------------------------
Rietveld 56 2611 LM Delft The Netherlands
-----------------------------------------------
Claudia Mens | claudia@petr.com
mobile +31 6 41 367 689 | buro +31 15 887 1233
-----------------------------------------------
|
DrawBot does not do any calculations to retrieve the position of the first line. That's all CoreText. DrawBot just draws glyph runs at a specific position. This document should describe how CoreText is using the different 'typographical' terms: https://developer.apple.com/library/content/documentation/StringsTextFonts/Conceptual/TextAndWebiPhoneOS/TypoFeatures/TextSystemFeatures.html the |
but you can calculate the pos super precise :) (but import random as rnd
point_size = 100
line_height = 50
t = "Hello World"
x, y = 68, 672
font_names = ['Times']
font_names.extend(rnd.sample(installedFonts(), 9))
boxWidth, boxHeight = 800, 500
for font_name in font_names:
newPage(1000, 1000)
single = FormattedString()
single.font(font_name, point_size)
single.lineHeight(line_height)
single += font_name
text(single, (x, y))
multi = FormattedString()
multi.font(font_name, point_size)
multi.lineHeight(line_height)
multi += t * 100
box = (x+ 100,
y-boxHeight,
boxWidth,
boxHeight)
# get the pos of the first line
startX, startY = textBoxBaselines(multi, box)[0]
# move the box back towards that first line
save()
translate(0, y-startY)
textBox(multi, box)
restore()
save()
stroke(1, 0, 0)
fill(None)
rect(*box)
restore() |
Thank you Frederik. So what’s needed to make
|
Maybe I have to push a new update... will check |
Does not work in 3.97 yet. |
this should work in the latest versions... |
@frankrolf, can this be closed? |
This can indeed be closed. |
In a text box, how does DrawBot specify the position of the first baseline for a given font?
I am currently working on a script that layers different fonts, and need to calculate the baseline offset – unfortunately that’s trickier than expected.
A common assumption is just subtracting the
hhea.ascent
value from the top of the text frame, but it’s not that simple – especially in fonts wherehhea.ascent
+|hhea.descent|
!= 1000.Here is my test data (for simplicity’s sake, font size = UPM = 1000):
This may have been solved by @petrvanblokland – I assume pageBot can deal with baselines?
The text was updated successfully, but these errors were encountered: