Skip to content
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

fallbackfont for content title display #2091

Merged
merged 1 commit into from
Jan 18, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions components/ItemGrid/GridItem.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
<PlayedCheckmark id="playedIndicator" color="#00a4dcFF" width="90" height="60" opacity=".99" translation="[201, 0]" visible="false" />
</Poster>
<Poster id="itemIcon" width="50" height="50" translation="[230,10]" />
<Label id="posterText" width="280" height="415" translation="[5,5]" horizAlign="center" vertAlign="center" ellipsizeOnBoundary="true" wrap="true" />
<jfLabel id="posterText" width="280" height="415" translation="[5,5]" horizAlign="center" vertAlign="center" ellipsizeOnBoundary="true" wrap="true" />
</maskGroup>
<ScrollingLabel id="itemText" horizAlign="center" font="font:SmallSystemFont" maxWidth="290" repeatCount="0" visible="false" />
<jfScrollingLabel id="itemText" horizAlign="center" fallbackFontSize="24" maxWidth="290" repeatCount="0" visible="false" />
</children>
<interface>
<field id="itemContent" type="node" onChange="itemContentChanged" />
Expand Down
2 changes: 1 addition & 1 deletion components/ItemGrid/ItemGrid.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

<RowList opacity="0" id="genrelist" translation="[120, 160]" showRowLabel="true" itemComponentName="GridItemSmall" numColumns="1" numRows="3" vertFocusAnimationStyle="fixed" itemSize="[1900, 360]" rowItemSize="[ [230, 320] ]" rowItemSpacing="[ [20, 0] ]" itemSpacing="[0, 60]" />

<Label translation="[0,540]" id="emptyText" font="font:LargeSystemFont" width="1910" horizAlign="center" vertAlign="center" height="64" visible="false" />
<jfLabel translation="[0,540]" id="emptyText" font="font:LargeSystemFont" width="1910" horizAlign="center" vertAlign="center" height="64" visible="false" />
<ItemGridOptions id="options" visible="false" />
<Animation id="backroundSwapAnimation" duration="1" repeat="false" easeFunction="linear">
<FloatFieldInterpolator id="fadeinLoading" key="[0.0, 1.0]" keyValue="[ 0.00, 0.25 ]" fieldToInterp="backdropTransition.opacity" />
Expand Down
2 changes: 1 addition & 1 deletion components/JFOverhang.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<children>
<LayoutGroup id="overlayLeftGroup" layoutDirection="horiz" translation="[54, 54]" itemSpacings="60">
<Poster id="overlayLogo" uri="pkg:/images/logo.png" height="66" width="191" />
<ScrollingLabel id="overlayTitle" font="font:LargeSystemFont" vertAlign="center" height="64" maxWidth="1100" repeatCount="0" />
<jfScrollingLabel id="overlayTitle" vertAlign="center" height="64" maxWidth="1100" repeatCount="0" />
</LayoutGroup>
<LayoutGroup id="overlayRightGroup" layoutDirection="horiz" itemSpacings="30" translation="[1766, 53]" horizAlignment="right">
<Label id="overlayCurrentUser" font="font:MediumSystemFont" width="300" horizAlign="right" vertAlign="center" height="64" />
Expand Down
4 changes: 2 additions & 2 deletions components/home/HomeItem.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
<Rectangle id="progressBackground" visible="false" color="0x00000098" width="464" height="8" translation="[0,253]">
<Rectangle id="progress" color="#00a4dcFF" width="0" height="8" />
</Rectangle>
<ScrollingLabel id="itemText" horizAlign="center" vertAlign="center" font="font:SmallBoldSystemFont" height="64" maxWidth="456" translation="[8,267]" repeatCount="0" />
<Label id="itemTextExtra" horizAlign="left" vertAlign="center" font="font:SmallBoldSystemFont" height="32" width="456" translation="[8,300]" visible="false" color="#777777FF" />
<jfScrollingLabel id="itemText" horizAlign="center" vertAlign="center" font="font:SmallBoldSystemFont" height="64" maxWidth="456" translation="[8,267]" repeatCount="0" />
<jfLabel id="itemTextExtra" horizAlign="left" vertAlign="center" font="font:SmallBoldSystemFont" height="32" width="456" translation="[8,300]" visible="false" color="#777777FF" />

<Animation id="showProgressBar" duration="0.5" repeat="false" easeFunction="linear">
<FloatFieldInterpolator id="showProgressBarField" key="[0.0, 1.0]" fieldToInterp="progress.width" />
Expand Down
24 changes: 24 additions & 0 deletions components/jflabel/jflabel.bs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
sub init()
m.top.id = "jflabel"
m.top.observeField("text", "onText")
setFallbackfont()
end sub

sub onText()
setFallbackfont()
end sub

sub setFallbackfont()
if m.global.fallbackFont = invalid or m.top.font.id = "jffallbackfont" then return
fontSize = m.top.font.size

fallbackFontSize = m.top.fallbackFontSize
if getInterface(fallbackFontSize, "ifInteger") <> invalid and fallbackFontSize > 1 then fontSize = fallbackFontSize

m.top.font = m.global.fallbackFont.clone(true)
m.top.font.size = fontSize
end sub

sub onFallbackFontSize()
if m.top.font.size <> m.top.fallbackFontSize then m.top.font.size = m.top.fallbackFontSize
end sub
6 changes: 6 additions & 0 deletions components/jflabel/jflabel.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<component name="jflabel" extends="label">
<interface>
<field id="fallbackFontSize" type="integer" onChange="onFallbackFontSize"/>
</interface>
</component>
24 changes: 24 additions & 0 deletions components/jfscrollinglabel/jfscrollinglabel.bs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
sub init()
m.top.id = "jfscrollinglabel"
m.top.observeField("text", "onText")
setFallbackfont()
end sub

sub onText()
setFallbackfont()
end sub

sub setFallbackfont()
if m.global.fallbackFont = invalid or m.top.font.id = "jffallbackfont" then return
fontSize = m.top.font.size

fallbackFontSize = m.top.fallbackFontSize
if getInterface(fallbackFontSize, "ifInteger") <> invalid and fallbackFontSize > 1 then fontSize = fallbackFontSize

m.top.font = m.global.fallbackFont.clone(true)
m.top.font.size = fontSize
end sub

sub onFallbackFontSize()
if m.top.font.size <> m.top.fallbackFontSize then m.top.font.size = m.top.fallbackFontSize
end sub
6 changes: 6 additions & 0 deletions components/jfscrollinglabel/jfscrollinglabel.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<component name="jfscrollinglabel" extends="scrollinglabel">
<interface>
<field id="fallbackFontSize" type="integer" onChange="onFallbackFontSize" />
</interface>
</component>
2 changes: 1 addition & 1 deletion components/video/OSD.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<Poster uri="pkg:/images/osdBackground.png" width="1920" height="279" />

<LayoutGroup id="videoInfo" layoutDirection="vert" translation="[103,61]">
<ScrollingLabel id="itemTitle" font="font:LargeBoldSystemFont" maxWidth="1400" />
<jfScrollingLabel id="itemTitle" font="font:LargeBoldSystemFont" maxWidth="1400" />
<LayoutGroup id="videoInfo" layoutDirection="horiz" translation="[103,61]">
<Label id="itemSeason" font="font:MediumSystemFont" color="0xffffffFF" />
<Label id="itemEpisode" font="font:MediumSystemFont" color="0xffffffFF" />
Expand Down
4 changes: 4 additions & 0 deletions components/video/VideoPlayerView.bs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ sub init()
m.top.retrievingBar.filledBarBlendColor = m.global.constants.colors.blue
m.top.bufferingBar.filledBarBlendColor = m.global.constants.colors.blue
m.top.trickPlayBar.filledBarBlendColor = m.global.constants.colors.blue

m.customTitle = createObject("roSgNode", "jflabel")
m.top.customTitle = m.customTitle
end sub

' handleChapterSkipAction: Handles user command to skip chapters in playing video
Expand Down Expand Up @@ -410,6 +413,7 @@ sub onVideoContentLoaded()
m.chapters = videoContent[0].chapters
m.top.showID = videoContent[0].showID

m.customTitle.text = m.top.content.title
m.osd.itemTitleText = m.top.content.title

' If video is an episode, attempt to add season and episode numbers to OSD
Expand Down
45 changes: 28 additions & 17 deletions source/Main.bs
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,12 @@ sub Main (args as dynamic) as void
m.global.addFields({ app_loaded: false, playstateTask: playstateTask, sceneManager: sceneManager, launchSource: "" })
m.global.addFields({ queueManager: CreateObject("roSGNode", "QueueManager") })
m.global.addFields({ audioPlayer: CreateObject("roSGNode", "AudioPlayer") })
m.global.addField("fallbackFont", "node", true)

app_start:
' First thing to do is validate the ability to use the API
if not LoginFlow() then return
loadFallbackFont() 'load custom font if enabled

' remove login scenes from the stack
sceneManager.callFunc("clearScenes")
Expand All @@ -55,23 +57,6 @@ sub Main (args as dynamic) as void

m.scene.observeField("exit", m.port)

' Downloads and stores a fallback font to tmp:/
configEncoding = api.system.GetConfigurationByName("encoding")

if isValid(configEncoding) and isValid(configEncoding.EnableFallbackFont)
if configEncoding.EnableFallbackFont
re = CreateObject("roRegex", "Name.:.(.*?).,.Size", "s")
filename = APIRequest("FallbackFont/Fonts").GetToString()
if isValid(filename)
filename = re.match(filename)
if isValid(filename) and filename.count() > 0
filename = filename[1]
APIRequest("FallbackFont/Fonts/" + filename).gettofile("tmp:/font")
end if
end if
end if
end if

' only show whats new popup and update lastRunVersion on prod
if not m.global.app.isDev
' has the current user ran this version before?
Expand Down Expand Up @@ -899,3 +884,29 @@ sub Main (args as dynamic) as void
end while

end sub

sub loadFallbackFont()
configEncoding = api.system.GetConfigurationByName("encoding")
if not configEncoding.EnableFallbackFont then return

fontFiles = APIRequest("FallbackFont/Fonts").GetToString()
fontFilesList = parseJson(fontFiles)
isFirstFont = getInterface(fontFilesList, "ifArray") <> invalid and fontFilesList[0] <> invalid and fontFilesList[0].name <> invalid
if not isFirstFont then return

fontFilename = fontFilesList[0].name 'pickup the first font
if fontFilename = invalid then return

APIRequest("FallbackFont/Fonts/" + fontFilename).gettofile("tmp:/font")

fs = CreateObject("roFileSystem")
if fs.Exists("tmp:/font")
getFallbackFont = function() as object
font = CreateObject("roSGNode", "Font")
font.id = "jffallbackfont"
font.uri = "tmp:/font"
return font
end function
m.global.fallbackFont = getFallbackFont()
end if
end sub
Loading