Fonts In TemplatedMultiContent...

Moderators: Gully, peteru

Post Reply
IanSav
Uber Wizard
Posts: 16846
Joined: Tue May 29, 2007 15:00
Location: Melbourne, Australia

Fonts In TemplatedMultiContent...

Post by IanSav » Wed Feb 24, 2016 09:11

Hi Prl,

Can I please have some assistance with fonts in TemplatedMultiContent structures. I am adding user selectable fonts into OverlayHD. I am doing this via the font "Alias" mechanism. This will allow fonts to be change much like I currently change colours. This is working perfectly across the whole skin except for the gFont code in a TemplatedMultiContent structuures. If I use a font alias in a gFont definition then no text is displayed. From the outside this looks like the problem where colour names could not be used in TemplatedMultiContent structures until you fixed that area of the code.

I would welcome any assistance or fixes that you can provide.

Regards,
Ian.

prl
Wizard God
Posts: 32709
Joined: Tue Sep 04, 2007 13:49
Location: Canberra; Black Mountain Tower transmitters

Re: Fonts In TemplatedMultiContent...

Post by prl » Wed Feb 24, 2016 10:25

Can you give me a concrete example of what you've done?
Peter
T4 HDMI
U4, T4, T3, T2, V2 test/development machines
Sony BDV-9200W HT system
LG OLED55C9PTA 55" OLED TV

IanSav
Uber Wizard
Posts: 16846
Joined: Tue May 29, 2007 15:00
Location: Melbourne, Australia

Re: Fonts In TemplatedMultiContent...

Post by IanSav » Wed Feb 24, 2016 10:42

Hi Prl,

In the original skin I had:

Code: Select all

	<fonts>
		<font name="Regular" filename="nmsbd.ttf" scale="100" />
	<fonts>
while in the revised skin I have a structure:

Code: Select all

	<fonts>
		<font name="NemesisFlatline" filename="nmsbd.ttf" scale="100" />

		<alias name="HelpFont" font="NemesisFlatline" size="20" height="25" width="18" />
	</fonts>
Originally in the HelpMenu screen I had:

Code: Select all

		<widget source="list" render="Listbox" position="400,80" size="830,500" backgroundColor="MenuBackground" backgroundColorSelected="MenuSelected" enableWrapAround="1" foregroundColor="MenuText" foregroundColorSelected="MenuTextSelected" scrollbarMode="showOnDemand" transparent="0">
			<convert type="TemplatedMultiContent">
				{
				"templates":
					{
					"default": (25,
						[
						MultiContentEntryText(pos = (0, 0), size = (810, 25), font = 0, flags = RT_HALIGN_LEFT | RT_VALIGN_CENTER, text = 1),  # Help label
						MultiContentEntryText(pos = (20, 0), size = (790, 25), font = 0, flags = RT_HALIGN_LEFT | RT_VALIGN_CENTER, text = 2)  # Help item
						]),
					"extended": (50,
						[
						MultiContentEntryText(pos = (0, 0), size = (810, 25), font = 0, flags = RT_HALIGN_LEFT | RT_VALIGN_CENTER, text = 1),  # Help label
						MultiContentEntryText(pos = (20, 0), size = (790, 25), font = 0, flags = RT_HALIGN_LEFT | RT_VALIGN_CENTER, text = 2),  # Help item
						MultiContentEntryText(pos = (0, 25), size = (810, 25), font = 1, flags = RT_HALIGN_LEFT | RT_VALIGN_CENTER, color = "DarkGrey", color_sel = "Silver", text = 3),  # Help label (tupple with 1)
						MultiContentEntryText(pos = (20, 25), size = (790, 25), font = 1, flags = RT_HALIGN_LEFT | RT_VALIGN_CENTER, color = "DarkGrey", color_sel = "Silver", text = 4),  # Help item (tupple with 2)
						])
					},
				"fonts": [gFont("Regular", 20), gFont("Regular", 20)],
				"itemHeight": 25
				}
			</convert>
which works perfectly but in the revised skin I have:

Code: Select all

		<widget source="list" render="Listbox" position="400,80" size="830,500" backgroundColor="MenuBackground" backgroundColorSelected="MenuSelected" enableWrapAround="1" foregroundColor="MenuText" foregroundColorSelected="MenuTextSelected" scrollbarMode="showOnDemand" transparent="0">
			<convert type="TemplatedMultiContent">
				{
				"templates":
					{
					"default": (25,
						[
						MultiContentEntryText(pos = (0, 0), size = (810, 25), font = 0, flags = RT_HALIGN_LEFT | RT_VALIGN_CENTER, text = 1),  # Help label
						MultiContentEntryText(pos = (20, 0), size = (790, 25), font = 0, flags = RT_HALIGN_LEFT | RT_VALIGN_CENTER, text = 2)  # Help item
						]),
					"extended": (50,
						[
						MultiContentEntryText(pos = (0, 0), size = (810, 25), font = 0, flags = RT_HALIGN_LEFT | RT_VALIGN_CENTER, text = 1),  # Help label
						MultiContentEntryText(pos = (20, 0), size = (790, 25), font = 0, flags = RT_HALIGN_LEFT | RT_VALIGN_CENTER, text = 2),  # Help item
						MultiContentEntryText(pos = (0, 25), size = (810, 25), font = 1, flags = RT_HALIGN_LEFT | RT_VALIGN_CENTER, color = "DarkGrey", color_sel = "Silver", text = 3),  # Help label (tupple with 1)
						MultiContentEntryText(pos = (20, 25), size = (790, 25), font = 1, flags = RT_HALIGN_LEFT | RT_VALIGN_CENTER, color = "DarkGrey", color_sel = "Silver", text = 4),  # Help item (tupple with 2)
						])
					},
				"fonts": [gFont("HelpFont", 20), gFont("HelpFont", 20)],
				"itemHeight": 25
				}
			</convert>
and with this tweaked code the text no longer appears. I presume because there was a problem accessing the Alias font.

Does this sufficiently explain what I am trying to do?

Regards,
Ian.

prl
Wizard God
Posts: 32709
Joined: Tue Sep 04, 2007 13:49
Location: Canberra; Black Mountain Tower transmitters

Re: Fonts In TemplatedMultiContent...

Post by prl » Wed Feb 24, 2016 11:12

Yes, that's clear now, and it's what I thought. Font aliases aren't used by gFonts.

Font aliasing is done by skin.parseFont(). Fortunately, it returns a gFont(), so in principle, changing
gFont("HelpFont", 20)
to
parseFont("HelpFont;20", ((1, 1), (1, 1)))
should work .

Use
parseFont("HelpFont", ((1, 1), (1, 1)))
if you want to use the alias's default height.

But Converter.TemplatedMultiContent doesn't import skin.parseFont, so for that to work, you'd need to add
from skin import parseFont
to Converter/TemplatedMultiContent.py

I don't think that hacks like the eval() in the standard skins' GeneralSetup can work because the TemplatedMultiContent's template is passed as an argument to eval(), and so it needs to be an expression, not a suite/sequence of statements.
Peter
T4 HDMI
U4, T4, T3, T2, V2 test/development machines
Sony BDV-9200W HT system
LG OLED55C9PTA 55" OLED TV

IanSav
Uber Wizard
Posts: 16846
Joined: Tue May 29, 2007 15:00
Location: Melbourne, Australia

Re: Fonts In TemplatedMultiContent...

Post by IanSav » Wed Feb 24, 2016 23:25

Hi Prl,

Is there a way to change TemplatedMultiContent so that use of Alias fonts can be made transparent to the converter skin code? Something like look at the skin "gFont" parameter and see if the font name is actually an alias and make the substitution before executing the "gFont" code.

Regards,
Ian.

prl
Wizard God
Posts: 32709
Joined: Tue Sep 04, 2007 13:49
Location: Canberra; Black Mountain Tower transmitters

Re: Fonts In TemplatedMultiContent...

Post by prl » Thu Feb 25, 2016 11:03

IanSav wrote:...
Is there a way to change TemplatedMultiContent so that use of Alias fonts can be made transparent to the converter skin code? Something like look at the skin "gFont" parameter and see if the font name is actually an alias and make the substitution before executing the "gFont" code.
...
My suggested change will do exactly that. It will use an alias if the name is an alias and it will use the font if the name is the name of an actual font. It's almost exactly what is done with the font name for a "font=" attribute. The "font=" attribute makes use of the font scale parameters (the ((1, 1), (1, 1)) argument to parseFont() in my example) passed into the AttributeParser, but widget's scale is not readily accessible from TemplatedMultiContent anyway. parseFont() is the function used to apply the value of the "font=" attribute.
Peter
T4 HDMI
U4, T4, T3, T2, V2 test/development machines
Sony BDV-9200W HT system
LG OLED55C9PTA 55" OLED TV

Post Reply

Return to “Developers Community”