Font size to Moho units

Moho allows users to write new tools and plugins. Discuss scripting ideas and problems here.

Moderators: Víctor Paredes, Belgarath, slowtiger

Post Reply
ggoblin
Posts: 266
Joined: Wed Jan 19, 2022 2:09 pm

Font size to Moho units

Post by ggoblin »

Just trying to understand how to work with text from a script. Any pointers, best practice, etc., would be most appreciated.

How does font size correspond with moho units?

Is there a formula to convert pt size to the size moho will render a font at 100% scale?

Can we determine what size a font is in moho units when rendered at 100% scale ?

What do the values for leading and kerning correspond to? In other software like photoshop this is again measured in pts.

From what I can tell the text API is wrapped up in a single command InsertText. When I did a search for InsertText in MohoScripts.com there are no scripts that use it. Mohoscripting.com does have a useful page on it at https://mohoscripting.com/methods/85

I see there is a

Code: Select all

int32 TextSize
and

Code: Select all

real LineWidth
parameters in InsertTextParams ?

There is also a

Code: Select all

lineOffset  int32
parameter in InsertText..

Thank you for any help.
User avatar
LeviFiction
Posts: 18
Joined: Thu Jul 10, 2014 4:19 am

Re: Font size to Moho units

Post by LeviFiction »

Seeing text change size with different fonts all at 100% I don't think it's strictly related to the size of the project like Moho points are. Or if they are, it's an equation taking EMs or FUnits. Could be wrong, but if I'm right there would be no way to determine the size without reading the font file itself. In which case it would be best to take the resulting size of the layer after a font has been made and just scale it to what you need.
User avatar
hayasidist
Posts: 3536
Joined: Wed Feb 16, 2011 8:12 pm
Location: Kent, England

Re: Font size to Moho units

Post by hayasidist »

yeah - I have to agree with LeviFiction here -- there doesn't seem to be any way to work that out -- just to add to LF's observations - A quick test seems to show that descenders / ascenders on a letter "reset" the lower / upper y level (i.e. the "line" along which letters would "usually" be written moves depending on whether there are ascenders or descenders in the text) [e.g. if text you enter with no ascenders/descenders is bounded with y = +/- 0.15 -- adding an ascender or descender letter -> the bounds change to +/- 0.2; add the other of descender / ascender to that and the bounds are +/- 0.25] It appears to me to designed for visual rather than parametric application!
ggoblin
Posts: 266
Joined: Wed Jan 19, 2022 2:09 pm

Re: Font size to Moho units

Post by ggoblin »

Thank you LeviFiction and Hayasidist for looking in to this. I have to agree I'm clueless as to what 100% size means in regards to the text, and as Hayasidist observed, the text is centred so is different each time depending on what ascenders or descenders the characters of the text contain.

There seems to be very little support in the API for text layers.

As far as I can tell you dont have any access to inside EXISTING text layers from script. All you can do is layer level actions like delete the layer. You can convert the text layer to a vector layer, but that destroys all its meta data that we are after. I suppose you can make out what text the layer hides by reading the layers name, but thats it - no info on font, size, kerning, etc.

The closest you get is to examine the buffer of the CreateTextObject which was last used to create text, to see what setting were used, but this is hardly reliable - if you have several text layers there is no indication what layer, if any, this information may refer to.

You can create NEW text layers from script, but thats not really what I need for my requirement. And of course as soon as you create the new text layer you loose all control to see inside it, or modify it from script.

All this seems very bleak, please tell me I'm wrong and show me what I'm missing. :)

Thank you.
User avatar
synthsin75
Posts: 9982
Joined: Mon Jan 14, 2008 11:20 pm
Location: Oklahoma
Contact:

Re: Font size to Moho units

Post by synthsin75 »

Welcome to the Moho API, where we have deceptively wide access to many things, some of which we had to beg for years to get, and longstanding lack of access to others.

Generally, API access is only given where needed for stock tools. Many of us have gotten use to this over many years.
ggoblin
Posts: 266
Joined: Wed Jan 19, 2022 2:09 pm

Re: Font size to Moho units

Post by ggoblin »

synthsin75 wrote: Mon Jul 18, 2022 7:57 pm Welcome to the Moho API, where we have deceptively wide access to many things, some of which we had to beg for years to get, and longstanding lack of access to others.

Generally, API access is only given where needed for stock tools. Many of us have gotten use to this over many years.
Hahaha!

Well its helps knowing that for once its a limitation of the API, and not my ignorance. :D
ggoblin
Posts: 266
Joined: Wed Jan 19, 2022 2:09 pm

Re: Font size to Moho units

Post by ggoblin »

I guess I'm learning like the rest of you to try and work around the API limitations. I got it to do what I wanted, be it in a round about non ideal way.. but it still works.

I was looking at automating my whiteboard style text animation.

The elegant technique is strider2000's as described here: http://www.lostmarble.com/forum/viewtopic.php?t=34767

I just modified it to use transparent masks and whilst he was using point animation to reveal the text, I chose to use layer translation to achieve the same as it was more convenient when automating any generic text. The video below shows in realtime how I create a simple 4 line text animation using my unfinished script. There is more intervention needed by the user than I would like, but most of it is due to the API limitations of scripts not being able to see inside text layers..so the user has to help it along. Main thing is it works and is a lot faster than if I had to manually do it for each text line animation. I know its very rough (like hand disappearing suddenly at end) .. there are some parameters I should have tuned, and the script itself needs a lot more work.

Image

The the video below is an under the bonnet view of what the script is generating

Image

The final generated video - the syncing isn't too shabby considering its generated by script and hasn't been fine tuned by hand. (I know its too fast, but thats a user issue not the scripts fault)

Image

I know the script needs a lot more work, but I'm pleased - its a little progress in my journey to learning Moho :D

Any advice greatly welcomed. Thank you for your help.
Post Reply