Giter VIP home page Giter VIP logo

Comments (6)

chrissimpkins avatar chrissimpkins commented on June 24, 2024 1

Thanks for the note! To clarify your request here, you would like the report command output to be available in a table in the binary? Where / how would it be ideal to access it?

My initial concern about this is that a tool could change the metrics data in the font and not update the information that is recorded by font-line in the binary. How should we approach that?

from font-line.

chrissimpkins avatar chrissimpkins commented on June 24, 2024 1

Ah, I see. Are you familiar with Python? This should be reasonably straightforward using the fonttools library and your config file format of choice.

from font-line.

chrissimpkins avatar chrissimpkins commented on June 24, 2024 1

No problem. The fontTools.ttLib.TTFont documentation will be a good place to start. TTFont is a font object that is instantiated from a binary file path. It provides access to all of the OpenType tables that you will need to edit and is the data structure that is used in font-line for read/write access to the metrics data.

Have a look at

# Vertical metrics values as integers
self.os2_typo_ascender = tt["OS/2"].sTypoAscender
self.os2_typo_descender = tt["OS/2"].sTypoDescender
self.os2_win_ascent = tt["OS/2"].usWinAscent
self.os2_win_descent = tt["OS/2"].usWinDescent
self.os2_typo_linegap = tt["OS/2"].sTypoLineGap
try:
self.os2_x_height = tt["OS/2"].sxHeight
except AttributeError:
self.os2_x_height = "---- (OS/2 table does not contain sxHeight record)"
try:
self.os2_cap_height = tt["OS/2"].sCapHeight
except AttributeError:
self.os2_cap_height = "---- (OS/2 table does not contain sCapHeight record)"
self.hhea_ascent = tt["hhea"].ascent
self.hhea_descent = tt["hhea"].descent
self.hhea_linegap = tt["hhea"].lineGap
self.ymax = tt["head"].yMax
self.ymin = tt["head"].yMin
self.units_per_em = tt["head"].unitsPerEm
# Bit flag checks
self.fsselection_bit7_mask = 1 << 7
self.fsselection_bit7_set = (
tt["OS/2"].fsSelection & self.fsselection_bit7_mask
) != 0
# Calculated values
self.os2_typo_total_height = self.os2_typo_ascender + abs(self.os2_typo_descender)
self.os2_win_total_height = self.os2_win_ascent + self.os2_win_descent
self.hhea_total_height = self.hhea_ascent + abs(self.hhea_descent)
self.hhea_btb_distance = self.hhea_total_height + self.hhea_linegap
self.typo_btb_distance = self.os2_typo_total_height + self.os2_typo_linegap
self.win_external_leading = self.hhea_linegap - (
(self.os2_win_ascent + self.os2_win_descent)
- (self.hhea_ascent - self.hhea_descent)
)
if self.win_external_leading < 0:
self.win_external_leading = 0
self.win_btb_distance = (
self.os2_win_ascent + self.os2_win_descent + self.win_external_leading
)
self.typo_to_upm = 1.0 * self.typo_btb_distance / self.units_per_em
self.winascdesc_to_upm = 1.0 * self.win_btb_distance / self.units_per_em
self.hheaascdesc_to_upm = 1.0 * self.hhea_btb_distance / self.units_per_em
for details on how to get at the metrics data in each of the relevant OT tables. In that block of font-line source, tt is the TTFont object. What you will want to do is edit those data with the desired values and then save the font to disk. save takes a file path and allows you to either save in place or on a different path. I think that the only missing piece will be to decide how you want to configure the data. JSON is supported in the Python stdlib. There are 3rd party packages on PyPI for toml, yaml, etc. Those should be the pieces to get to where you want to go!

Let me know if you run into any issues and if you come up with something that others can use!

from font-line.

charityrolfson433 avatar charityrolfson433 commented on June 24, 2024 1

Thanks for taking all this time to help me. I will try to get something out of it. Thank you again.

from font-line.

charityrolfson433 avatar charityrolfson433 commented on June 24, 2024

@chrissimpkins i am not very familiar in this field, also not very techy to with all the terminology. so you have to pardon me for my limited knowledge.

I want to change the Metrics table values which are generated in the text file (ie, [head] yMax:, [head] yMin:, [OS/2] TypoAscender:... and other values) to gain the line-gap according to my personal taste, where I know the default way to change is to use the percentage command.

I also not that good or able to tell you how can we achieve that. My thoughts are this: We generate the Metrics table in a text file and will it be possible to write back the modified values to the font anyhow? something like font-line font-report.txt > font.ttf may be?

i can do it with any font-editor app/software (fontforge or anything of such sort) but as command line utilities are always faster in working with, also if I ever in need of editing in bulk amount it would be a perfect choice.

from font-line.

charityrolfson433 avatar charityrolfson433 commented on June 24, 2024

Thank you very much for the information.
Yes I am a little familiar with Python and fonttools. I sometimes use fonttool's TTX but not very advanced user. Can you link me to some tutorial or article from where people like me (with limited knowledge) can learn about what I am trying to achieve here?

from font-line.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.