Page 1 of 3
fontMenu function with submenus
Posted: Wed Aug 07, 2024 2:31 am
by foxtrot47
OpenXTalkPaul wrote: ↑Tue Aug 06, 2024 8:41 pm
1) Handler with a script that returns a fonts lists formatted for a menu/menu-button text where the fonts of the same family (like "Helvetica" for example) are grouped together in a sub-menu of the menu text list it returns. So the resulting menu text would have a sub-menu named "Helvetica" that has menu items "Helvetica Regular", "Helvetica Bold", "Helvetica Light", etc.
How about this?
Code: Select all
-- Returns a sorted list of fonts and supported styles in submenus
--
-- Usage: fontMenu()
-- fontMenu(true)
--
function fontMenu pExcludeFontName
local tFonts, tStyles, tResult
put fontNames() into tFonts
sort tFonts
repeat for each line tFontName in tFonts
-- Modify Fonts with parentheses so they're not disabled
replace "(" with "((" in tFontName
-- Add the Font to the List
put tFontName &cr after tResult
-- Add any Styles as submenus
put fontStyles(tFontName, 0) into tStyles
if tStyles is not empty then
-- Add the submenu
if pExcludeFontName is true then
-- Without the Font's name preceeding each style
replace cr with (cr & tab) in tStyles
put tab & tStyles &cr after tResult
else
-- Font name preceeds each style
replace cr with (cr & tab & tFontName & " ") in tStyles
put tab & tFontName && tStyles &cr after tResult
end if
end if
end repeat
return tResult
end fontMenu
Re: fontMenu function with submenus
Posted: Wed Aug 07, 2024 3:03 am
by OpenXTalkPaul
foxtrot47 wrote: ↑Wed Aug 07, 2024 2:31 am
OpenXTalkPaul wrote: ↑Tue Aug 06, 2024 8:41 pm
1) Handler with a script that returns a fonts lists formatted for a menu/menu-button text where the fonts of the same family (like "Helvetica" for example) are grouped together in a sub-menu of the menu text list it returns. So the resulting menu text would have a sub-menu named "Helvetica" that has menu items "Helvetica Regular", "Helvetica Bold", "Helvetica Light", etc.
How about this?
Code: Select all
-- Returns a sorted list of fonts and supported styles in submenus
--
-- Usage: fontMenu()
-- fontMenu(true)
--
function fontMenu pExcludeFontName
local tFonts, tStyles, tResult
put fontNames() into tFonts
sort tFonts
repeat for each line tFontName in tFonts
-- Modify Fonts with parentheses so they're not disabled
replace "(" with "((" in tFontName
-- Add the Font to the List
put tFontName &cr after tResult
-- Add any Styles as submenus
put fontStyles(tFontName, 0) into tStyles
if tStyles is not empty then
-- Add the submenu
if pExcludeFontName is true then
-- Without the Font's name preceeding each style
replace cr with (cr & tab) in tStyles
put tab & tStyles &cr after tResult
else
-- Font name preceeds each style
replace cr with (cr & tab & tFontName & " ") in tStyles
put tab & tFontName && tStyles &cr after tResult
end if
end if
end repeat
return tResult
end fontMenu
Great Thanks! Nice to have the option parameter to include or not the full font name. I'll try it out later.
There's a parameter option for fontNames("printer") that "printer" should list font's internal printer font names, that may help with missing font styles problem on Windows. Will have to do some testing on WIn10 later.
Re: fontMenu function with submenus
Posted: Wed Aug 07, 2024 3:43 am
by foxtrot47
OpenXTalkPaul wrote: ↑Wed Aug 07, 2024 3:03 am
Great Thanks! Nice to have the option parameter to include or not the full font name. I'll try it out later.
There's a parameter option for fontNames("printer") that "printer" should list font's internal printer font names, that may help with missing font styles problem on Windows. Will have to do some testing on WIn10 later.
Added support for the "printer" boolean, as well as a filter for the Language. However, I get the same number of fonts with "ansi" and the printer boolean set to true, so those still need to be tested.
Please try this updated version instead:
Code: Select all
-- Returns a sorted list of fonts and supported styles in submenus
--
-- Example: fontMenu()
-- fontMenu(true)
-- fontMenu(false, true)
-- fontMenu(false, false, "ansi")
--
-- Parameters: pExcludeFontName (boolean, default: false)
-- Style submenus will not include the parent font's name.
--
-- pPrinterOnly (boolean, default: false)
-- Limits output to fonts only available on the currently selected printer.
--
-- pTargetLanguage (string, default: empty)
-- Limits output to a specific language. Reference: fontLanguage()
--
function fontMenu pExcludeFontName, pPrinterOnly, pTargetLanguage
local tFonts, tLanguage, tStyles, tResult
-- Choose between Printer or System Fonts (defaults to system)
if pPrinterOnly is true then
put fontNames("printer") into tFonts
else
put fontNames() into tFonts
end if
-- Sort alphabetically
sort tFonts
repeat for each line tFontName in tFonts
-- Check if results should be limitied to a specific language
if pTargetLanguage is not empty then
put fontLanguage(tFontName) into tLanguage
if toLower(tLanguage) is not toLower(pTargetLanguage) then next repeat
end if
-- Modify Fonts with parentheses so they're not disabled
replace "(" with "((" in tFontName
-- Add the Font to the List
put tFontName &cr after tResult
-- Add any Styles as submenus
put fontStyles(tFontName, 0) into tStyles
if tStyles is not empty then
-- Add the submenu
if pExcludeFontName is true then
-- Without the Font's name preceeding each style
replace cr with (cr & tab) in tStyles
put tab & tStyles &cr after tResult
else
-- Font name preceeds each style
replace cr with (cr & tab & tFontName & " ") in tStyles
put tab & tFontName && tStyles &cr after tResult
end if
end if
end repeat
return tResult
end fontMenu
Re: fontMenu function with submenus
Posted: Wed Aug 07, 2024 7:24 am
by OpenXTalkPaul
OK, that's not quite what I had in mind. I want to group the family together based on their internal font name. Otherwise it looks like this:

- Screen Shot 2024-08-07 at 2.40.09 AM.png (227.53 KiB) Viewed 5429 times
This is because, I believe the list of values that fontStyles returns only ever consist of fake-'bold', fake-'Italic', and combinations, which the engine's font render (pretty sure that's libPango) can generate styles for certain fonts (this seems to be mostly older TrueType format fonts). The font support in the engine seems to be somewhat dated and neglected (as is the case with other media, sound and graphics things in the engine).
This sort of 'fake font' generating mechanism was common in page layout programs such as Quark XPress back in the 1990s. Resulting font style mismatching problems could get extremely annoying, I know (I've worked in commercial printing for decades)!
The point is fontStyles (and I'd guess fontSizes too) are no longer representative of the actual fonts that may be installed and which may be contained in separate font files on disk even though they're part of the same fontFamily.
So what I was thinking was to create the groupings into fontFamilies based on matching words of the fontNames(printer), a Font family's base font-name is usually one or two words.
Then perhaps followed by one to four style words, so maybe also a check for keywords such as: Plain, Regular, Book, Bold, Heavy, Black, Light, Medium, Ultra-Light, Semimold, Condensed, Thin, etc. (That's a bunch of the commonly used 'styles', but there's quite a few more possibilities)
In the end I'd like all of those 'Avinir Next' fonts in my screen shot to be in a single sub-menu.
Some people have a TON of fonts
It is a more complicated task than one might imagine, and that's probably why some operating systems (like macOS) include a pre-made font picker API system-wide.
Re: fontMenu function with submenus
Posted: Wed Aug 07, 2024 8:54 am
by richmond62
On my Macintosh computers and my Linux boxes I tend to put fonts I generally use in a folder that is called something like this:
/user/home/library/fonts
it would be extremely useful if one could list ONLY the fonts in the user's font folder so users do not have to scroll through the '50 million' font their operating system plonks in the system/library/fonts folder.
Re: fontMenu function with submenus
Posted: Wed Aug 07, 2024 2:53 pm
by foxtrot47
OpenXTalkPaul wrote: ↑Wed Aug 07, 2024 7:24 am
In the end I'd like all of those 'Avinir Next' fonts in my screen shot to be in a single sub-menu.
Some people have a TON of fonts
It is a more complicated task than one might imagine, and that's probably why some operating systems (like macOS) include a pre-made font picker API system-wide.
I see what you're saying, thank you. I agree that the task is complicated and might require updates within the engine itself, especially when handling styles and such.
Regarding font grouping, I believe the simplest method is to assume the first word is the family name and group based on that. This would group "Avinir" and "Avinir Next" into the same family, which should be helpful for people with many fonts.
While it's possible to read each font's metadata to determine the family name, I've noticed that some font families don't identify themselves consistently. For example, the Liberation font on Linux Mint 21.2 has four variants, each with metadata showing they are individual fonts and not part of the same family. Using the directory structure to infer family names isn't reliable either, as font packs in the same directory might be incorrectly grouped together.
Here's an updated script with a new parameter that groups by the assumed family name (first word):
Code: Select all
-- Returns a sorted list of fonts and supported styles in submenus
--
-- Example: fontMenu()
-- fontMenu(true)
-- fontMenu(false, true)
-- fontMenu(false, false, "ansi")
-- fontMenu(true, false, , true)
--
-- Parameters: pExcludeFontName (boolean, default: false)
-- Style submenus will not include the parent font's name.
--
-- pPrinterOnly (boolean, default: false)
-- Limits output to fonts only available on the currently selected printer.
--
-- pTargetLanguage (string, default: empty)
-- Limits output to a specific language. Reference: fontLanguage()
--
-- pGroupByName (boolean, default: false)
-- Group first word of each font name as a "Family".
--
function fontMenu pExcludeFontName, pPrinterOnly, pTargetLanguage, pGroupByName
local tFonts, tLanguage, tStyles, tResult, tFontFamilies, tFamilyName, tFontSubMenu
local tSubFamilyName, tFullSubFamilyName, tSortedFamilies, tSortedSubFamilies
local tIgnore
-- Define the "special-purpose" font names to ignore
put "(Default)" & cr & \
"(Menu)" & cr & \
"(Message)" & cr & \
"(Styled Text)" & cr & \
"(System)" & cr & \
"(Text)" & cr & \
"(Tooltip)" into tIgnore
-- Choose between Printer or System Fonts (defaults to system)
if pPrinterOnly is true then
put fontNames("printer") into tFonts
else
put fontNames() into tFonts
end if
if pGroupByName is true then
-- Group fonts by family names
repeat for each line tFontName in tFonts
-- Skip special-purpose fonts
if tFontName is among the lines of tIgnore then next repeat
-- Check if results should be limited to a specific language
if pTargetLanguage is not empty then
put fontLanguage(tFontName) into tLanguage
if toLower(tLanguage) is not toLower(pTargetLanguage) then next repeat
end if
-- Identify the font family name
put word 1 of tFontName into tFamilyName
if tFamilyName is among the keys of tFontFamilies then
put tFontName & cr after tFontFamilies[tFamilyName]
else
put tFontName & cr into tFontFamilies[tFamilyName]
end if
end repeat
-- Get sorted list of family names
put the keys of tFontFamilies into tSortedFamilies
sort lines of tSortedFamilies
-- Create the result list with grouped fonts
repeat for each line tFamilyName in tSortedFamilies
put tFontFamilies[tFamilyName] into tFontSubMenu
put tFontSubMenu into tSortedSubFamilies
sort lines of tSortedSubFamilies
if the number of lines in tSortedSubFamilies > 1 then
put tFamilyName & cr after tResult
repeat for each line tFontName in tSortedSubFamilies
-- Identify the sub-family name
put word -1 of tFontName into tSubFamilyName
put tFamilyName && tSubFamilyName into tFullSubFamilyName
-- Add the sub-family to the list
put tab & tFullSubFamilyName & cr after tResult
-- Add any styles as sub-submenus
put fontStyles(tFontName, 0) into tStyles
if tStyles is not empty then
if pExcludeFontName is true then
replace cr with (cr & tab & tab) in tStyles
put tab & tab & tStyles & cr after tResult
else
replace cr with (cr & tab & tab & tFullSubFamilyName & " ") in tStyles
put tab & tab & tFullSubFamilyName && tStyles & cr after tResult
end if
else
put tab & tab & tFullSubFamilyName & cr after tResult
end if
end repeat
else
put tFamilyName & cr after tResult
repeat for each line tFontName in tSortedSubFamilies
put fontStyles(tFontName, 0) into tStyles
if tStyles is not empty then
if pExcludeFontName is true then
replace cr with (cr & tab) in tStyles
put tab & tStyles & cr after tResult
else
replace cr with (cr & tab & tFontName & " ") in tStyles
put tab & tFontName && tStyles & cr after tResult
end if
end if
end repeat
end if
end repeat
else
-- Don't group, but do sort alphabetically
sort tFonts
-- No grouping by family names
repeat for each line tFontName in tFonts
-- Skip special-purpose fonts
if tFontName is among the lines of tIgnore then next repeat
-- Check if results should be limited to a specific language
if pTargetLanguage is not empty then
put fontLanguage(tFontName) into tLanguage
if toLower(tLanguage) is not toLower(pTargetLanguage) then next repeat
end if
-- Get the font styles before we fix its name for display
put fontStyles(tFontName, 0) into tStyles
-- Modify Fonts with parentheses so they're not disabled
replace "(" with "((" in tFontName
-- Add the font to the list
put tFontName & cr after tResult
-- Add any styles as submenus
if tStyles is not empty then
if pExcludeFontName is true then
replace cr with (cr & tab) in tStyles
put tab & tStyles & cr after tResult
else
replace cr with (cr & tab & tFontName & " ") in tStyles
put tab & tFontName && tStyles & cr after tResult
end if
end if
end repeat
end if
-- Add the special-purpose fonts to the end of the list
put tIgnore into it
replace "(" with "((" in it
put it after tResult
return tResult
end fontMenu
Re: fontMenu function with submenus
Posted: Wed Aug 07, 2024 5:47 pm
by OpenXTalkPaul
Thanks, Version F is a lot closer!
However the idea is to have pWhich of the menuPick be usable to set the textFont props.
So i added this line to 'F' as a check:
set the textFont of me to pWhich
but with "Brush" font the resulting textFont was "Brush|plain" which is not a valid Fontname.
Personally I think every developer should've just stopped using that sort of fake-FontStyles that the engine can generate, like back in the 1990s or sooner. It is what it is, but I would not bother using the fontStyles syntax at all because more often then not you'll wind up with an invalid fontName. Even without the pipe | character, "Brush Plain" is also not the fontName, which is actually "Brush Script MT Italic", which breaks that 'first word is font family name' idea as the familyName should be "Brush Script MT"
I like having 50 million fonts, I would just like to make selecting them easier in the IDE.
We also need to account for fonts loaded into the engine using start using font syntax.
For a list of only the fonts in a particular directory, you could probably write a script that uses command line tools or something to get those fontNames / metadata, but our fontNames syntax doesn't return any file path information. 'The fontFilesInUse' does but only for fonts loaded by 'start using ...' here's some of the output show only IDE loaded fonts:
Code: Select all
/Users/paul/Desktop/OpenXTalk 1.963.1rc5.app/Contents/Tools/Toolset/resources/supporting_files/fonts/fontawesome.ttf
/Users/paul/Desktop/OpenXTalk 1.963.1rc5.app/Contents/Tools/Toolset/resources/supporting_files/fonts/SourceCodePro-Light.ttf
/Users/paul/Desktop/OpenXTalk 1.963.1rc5.app/Contents/Tools/Toolset/resources/supporting_files/fonts/lcideicons.ttf
/Users/paul/Desktop/OpenXTalk 1.963.1rc5.app/Contents/Tools/Toolset/resources/supporting_files/fonts/SourceCodePro-SemiboldIt.ttf
/Users/paul/Desktop/OpenXTalk 1.963.1rc5.app/Contents/Tools/Toolset/resources/supporting_files/fonts/SourceCodePro-Medium.ttf
I did look into TTF and OTF file format with the idea of parsing some relevant info directly from the font files on disk, but .OTF format looked quite a bit gnarly, and recent project to (partially) parse GIF format was enough to make me think twice about taking on that task, I just don't have time for that sort of thing right now.
An another alternative could be to use eXtension Builder FFI to select fonts with the OS's FontPicker API if there is one, but that's a bit tricky on Linux where different distros use different UI toolkits. I think it's probably best to have our own cross-platform xTalk based solutions for this sort of thing.
Re: fontMenu function with submenus
Posted: Wed Aug 07, 2024 5:54 pm
by tperry2x
I like this a lot.
It's certainly an improvement on scrolling (almost endlessly) to get to a font that I want.
There are a couple of things though. The first is probably easier to fix than the second.
The first thing is that both method A and method F can return a different font name.

- font-menu.png (21.13 KiB) Viewed 5369 times
The correct name of the font in my example would be "Commodore 64 Regular"

- samples.png (13.45 KiB) Viewed 5369 times
So what I'm wondering is, can method F return the font name as shown in method A, but work like method F?
(if that makes sense)
The second thing is going to be harder to implement I expect.
How hard would it be to possibly show a preview of the font when hovered over?:

- menus-with-sample.png (50.6 KiB) Viewed 5369 times
I'm guessing quite hard, due to menus (popups) not offering feedback in realtime while the user is scrolling through them.
I was working on
alternative menu-generating script, and wondered if some of that (or any part of that) is helpful? (very much in it's infancy - that is a beta version of the stack if you like).
Re: fontMenu function with submenus
Posted: Wed Aug 07, 2024 6:16 pm
by OpenXTalkPaul
I fed the idea to my ChatGPT xTalk topic and got some array based script back, haven't had time to look at it but it might be speedy to use associative array for doing the grouping, and then generate the menu text list from the resulting array the after. In general I would delimit family from style names by checking words 2 through 3 or 4 against a list of commonly used style keywords, only have one submenu per family [fontFamily also being root element of the array].
Re: fontMenu function with submenus
Posted: Wed Aug 07, 2024 6:38 pm
by OpenXTalkPaul
I'd like to add a this font family grouping to revMenubar but I also want this to add to the quarkXpress-measurments-like palette idea:
as well as adding font preview text (in the drop down section)
And maybe buttons for getting a rasterized pixel version of selection.
Re: fontMenu function with submenus
Posted: Wed Aug 07, 2024 6:53 pm
by tperry2x
I like that - reminds me of my Quark and InDesign days

but in a good way.

- textpal-strangeness.png (83.36 KiB) Viewed 5352 times
Some weirdness happening with fonts. The fonts chosen from the menu aren't what are being set in the field, so that's a bit strange - I like the palette idea though.
I was trying to help and trying to find out why it might be doing this. I can set the font with the normal inspector, and the textpal stack picks up on my font size and alignment, just not any font names.
edit:
I added the two lines in the script, so it populates the font menu (but I know we are changing that). I can set the text to "Roboto" now, but it always shows 'mixed' in the popup btn's label.

- hmm.png (131.35 KiB) Viewed 5344 times
@Paul - ah,
just seen your font-related post here. More reading...

Re: fontMenu function with submenus
Posted: Wed Aug 07, 2024 8:58 pm
by OpenXTalkPaul
tperry2x wrote: ↑Wed Aug 07, 2024 6:53 pm
I like that - reminds me of my Quark and InDesign days

but in a good way.
textpal-strangeness.png
Some weirdness happening with fonts. The fonts chosen from the menu aren't what are being set in the field, so that's a bit strange - I like the palette idea though.
Try selecting some text chunks in a field, then check what that menu says and then try changing to different Fonts for individual words/chars, the text needs to be still selected within the field on menuPick, it should also display the correct font name (or may be "mixed") depending on if the field or other parent object itself has it's own font assigned, or not (default empty), and if there is selection with several font styles used the selectedText styled text within the field it should show as "Mixed". But even if the styled text within the field may have a different fonts assigned already when you select the Field object itself, without any text chunk selected, the thing should show the font that's assigned to the field itself and which any newly adde text typed into the text field should automatically be assigned. At least that's how I think it should work. It checks the '
effective textFont' in the scripts IIRC.
Also keep in mind that this palette is still very much a work in progress, just one that I've sort of got away from working on for a while. I'm not sure if I have it updating its displayed info at all of the appropriate times.
Importantly the stack may behave differently when it's in Palette Mode versus behaving like topStack when you're editing the stack in edit mode.
Re: fontMenu function with submenus
Posted: Thu Aug 08, 2024 2:57 am
by OpenXTalkPaul
OK I spent some time tonight examine how other apps group fonts into font families.
Most apps are probably either extracting the metadata from the font files or useing existing OS APIs to do that,
but once there is a font data list they need to be put into a menu/font picker so people can select them.
This would be much easier if we could access the fonts metadata tables with xTalk syntax and get the font family names, but we don't have that capability presently.
We could just group our fonts based on the individual name, but then we still need some way of knowing which words are part of the font family name and which words are style names, in order to guess the family name. We can't just assume the font's family name is the first word of a font, because some font families have 2, 3, even 4 words to their name. The solution to this problem as I see it is to iterate backwards through the words of the font name, comparing each to a list of words that are known to be used as font style-names, then eliminating them from the name until we are left with what must be the family name. With that in mind I've gone through a bunch of fonts from various foundries and prepared a list of all of the words used as font style-name 'keywords' that I could find.
This first list is the most commonly used style names:
Code: Select all
Condensed
Cond
Compressed
Compact
Extended
Extra
ExtraCondensed
Extrabold
Extralight
Extrabold
Plain
Regular
Normal
Book
Italic
Oblique
Med
Medium
Demi
Demibold
Semi
Semibold
SemiCondensed
SemiExtended
Bold
Heavy
Black
Light
Ultra
Wide
Utlra
UltraLight
Ultrawide
Expanded
SuperLight
Thin
Narrow
This next list can be considered a secondary set of less commonly used style names.
I wouldn't
strictly assume these are
NOT part of the font's family's name,
but I have seen all of these used as Font style variations on a root font family.
Some of these are font weights like the numbers for variable width fonts, others are more like characteristics of the font's graphical quality or use case (such as Dingbats, Symbols, Smallcaps etc.)
Code: Select all
Serif
Sans
San Serif
Sanserif
Standard
Std
Roman
Solid
Script
Cursive
Mono
Monospace
Fantasy
Display
Title
Caps
Capitals
Small Caps
Smallcaps
Initials
Gothic
Text
Slanted
Nackslanted
Grotesk
Outline
Line
Keyline
Inline
Hairline
Shadow
Engraved
White
Round
Rounded
Initials
Ornaments
Ornamentals
Symbols
Dingbats
Decorations
Flourishes
Massive
Grand
Pro
OldStyle
Alt
One
Two
Three
Next
A
B
C
L
XL
XXL
100 through 900 stepping 100 (Variable Width Fonts)
Even if we had syntax to get the metadata/ names tables from the fonts the way some apps obviously do, that does NOT guarantee a font family will be perfectly grouped into a family sub-menu.
Consider this screenshot from Adobe Illustrator's Font Picker Drop down menu, notice that the OTF version of the selected Helvetica variation is NOT grouped with the rest of the font, which are from an older .TTF formated version of Helvetica.

- Screenshot 2024-08-07 at 10.26.54 PM.png (100.29 KiB) Viewed 5305 times
I suppose if you wanted to, you could group Helvetica Neue together with plain old Helvetica (but I've never seen an app do that).
My point is that sorting huge lists of fonts is hard.
Re: fontMenu function with submenus
Posted: Thu Aug 08, 2024 7:53 am
by tperry2x
I think it's important we are able to directly read the style name somehow.
It's not just limited to the styles you mentioned above, and a program like Fontographer allowed you to actually type
anything into the style field as a style property.
Meaning you could have "OpenXTalk 'Wacky' Regular" or "OXT scriptfont" (scriptfont being the style name).

- style-names.png (818.42 KiB) Viewed 5293 times
Edit:
If I recall, FontLab under MacOS X also allowed you to type anything in the style name.
Also, so does FontForge under Linux too.

- fforge-3819329985.png (55.28 KiB) Viewed 5267 times

- fontinfo-3025408117.png (47.42 KiB) Viewed 5267 times
Just to add to this, are "PS names" different potentially than "TTF names", or can more things be found under "Styleset names"... yeah, not easy at all.
Re: fontMenu function with submenus
Posted: Thu Aug 08, 2024 9:35 am
by richmond62
I have access to Fontlab 7 and 8, and they both let me pump out the 'Richmond totally bonkers' font.
Re: fontMenu function with submenus
Posted: Thu Aug 08, 2024 10:37 am
by richmond62

- fontNonsense1.png (13.21 KiB) Viewed 5278 times
-
Well this is, frankly, silly as, surely, the word that matters in these font names is not 'Noto', or 'Sans' (and that in itself is utter rubbish as you cannot have sans serif Nabatean), but 'Nabatean', or 'Sundanese'.
Let us suppose I have 2 Nabatean fonts on my system, one called 'Noto Sans Nabatean' and the other one (OK, this is made up by me) 'Nabatean normal'. How the TFF (no, those fonts are 'TTF' fonts, 'TFF' means something else) am I going to bung these 2 fonts into a submenu called 'Nabatean' without having to have a look-up table of unimaginable length of potential font names?
In the middle of last night I woke up with 'itemDelimiter' on my lips, thinking that were the itemDelimiter set to SPACE one could filter fonts such as
Richmond normal
Richmond bonkers
Fred Flintstone
Richmond crazy
Fred Hanover
into 2 groups: The 'Richmond' group, and the 'Fred' group: but, of course with those Noto fonts that is not really helpful at all.
Re: fontMenu function with submenus
Posted: Thu Aug 08, 2024 11:02 am
by richmond62

- fontNonsense2.png (109.21 KiB) Viewed 5274 times
-
So, if you will focus on the right-hand field:
Code: Select all
on mouseUp
put empty into fld "NOTO"
put 1 into PHONTS
put 1 into NOTOO
repeat until line PHONTS of fld "FONTZ" is empty
if item 1 of line PHONTS of fld "FONTZ" contains "Noto" then
put line PHONTS of fld "FONTZ" into line NOTOO of fld "NOTO"
add 1 to NOTOO
end if
add 1 to PHONTS
end repeat
end mouseUp
This sort of filtering is NOT really very helpful at all.
Re: fontMenu function with submenus
Posted: Fri Aug 09, 2024 12:01 am
by OpenXTalkPaul
I'm aware that you can use font editing tools to insert any style, weights, PS printer names, etc. into a generated font, even 'Bonkers' if you like. Just because you can does not mean that you should.
So (very late) last night I worked on an algorithm using mostly that first list I posted, and it did very nicely with my massive mix of commercial, fossil-freeware and FOSS fonts. I had it grouping them together quite nicely, with one exception.
I needed to add 'plain'/no-style for fonts with multiple styles, which I screwed up this after noon (I'll work on that some more later). The right-to-left removal of known styles that Im using is pretty good at getting to an accurate family grouping from fontNames() output.
For cases where you or someone else did use 'bonkers' as a style name, it would still list the full font name in the output list, but those odd-ball names wind up just not being grouped into a family, same as the screenshot from Adobe software that I posted. I don't see that as being anywhere near as important as it is to reduce the vertical length of font menus that make it take a full minute or more to find the font I'm looking for.
That's not to say that I'm not interested in alternative solutions for working with Fonts with xTalk, of course I am, It's just that I would prefer some minimum solution for making font menu more manageable and that doesn't rely on any external/extension or uses shell & command-line tools like 'FontConfig'.
I'm also taking out the Special Fonts like (Default), (Menu), etc. from the return list, I don't think anybody use those for anything?
Re: fontMenu function with submenus
Posted: Fri Aug 09, 2024 12:15 am
by OpenXTalkPaul
richmond62 wrote: ↑Thu Aug 08, 2024 11:02 am
fontNonsense2.png
-
So, if you will focus on the right-hand field:
Code: Select all
on mouseUp
put empty into fld "NOTO"
put 1 into PHONTS
put 1 into NOTOO
repeat until line PHONTS of fld "FONTZ" is empty
if item 1 of line PHONTS of fld "FONTZ" contains "Noto" then
put line PHONTS of fld "FONTZ" into line NOTOO of fld "NOTO"
add 1 to NOTOO
end if
add 1 to PHONTS
end repeat
end mouseUp
This sort of filtering is NOT really very helpful at all.
I see your point about Noto for variations for languages, but there could be an argument that those really are different base fonts anyway. They have different character mappings for different languages. There will always be some edge cases of fonts created in unusual or non-standard ways, you can't account for every possibility.
Another option could be to add some special checking for specific known fonts, groupings such as 'CSS Web Safe Font Set', and perhaps allowing user created grouping into custom font sets.
Again my goal is to produce a Font-picker menu that reduces the vertical length of the Font menu, because currently it's ridiculous, to the point of practically being unusable if you have a lot of fonts installed.
Re: fontMenu function with submenus
Posted: Fri Aug 09, 2024 2:35 am
by OpenXTalkPaul
I just looked again at the raw ascii text contents of several (Microsoft distributed) MonoType Arial .ttf font files with a text editor, and the only reference to actual Arial font family name it found from search for 'Arial' were in the copyright notices. So I don't think that extracting a font family name directly from the font files would be very easy. OTF format is basically an extended version of TTF so that's not going to be any easier to parse data from.
It may involve much more parsing of the file format than simply finding some 'magic number' offsets like in some RIFF based file formats. But I could be wrong about that:
https://learn.microsoft.com/en-us/typog ... me-strings
Searching for 'name' marker in Arial Rounded Bold does get a result, but what follows it is not plain ascii text:
Code: Select all
LX nameC%@o–Ÿpost,√A∆ç¥)prep∏Å›ƒuÇèXL_<ı¨>ãÌ¡ÈôͲú˛P {í í˛P ™˛ú˛ú {ÛÛr\Ïufiêö3Åö3øfMONO@ ”˛Rí∞ (Ê++@++
As I've mentioned the engine already uses hooks into libFreeType so I think that could be useful if I can bind to it with the XB FFI.
http://freetype.org/freetype2/docs/inde ... s-freetype