diff options
author | Sven Göthel <[email protected]> | 2024-02-03 01:14:10 +0100 |
---|---|---|
committer | Sven Göthel <[email protected]> | 2024-02-03 01:14:10 +0100 |
commit | 4ba099b97df41be220c4b2816c728e6b8cc1b037 (patch) | |
tree | 7c20f28515ed9d5dba71b0721c24b29c8d3d12eb /src/graphui/classes/com | |
parent | 7928ed90104f71fb53ae8201b3140b8e347b83ee (diff) |
Graph/GraphUI: Move getDefault*() to FontFactory and add {get,set}FallbackFont() + Font.getBestCoverage(..); Use fallback-font in MediaButton in case chosen font doesn't match (foreign languages, e.g. 'zho' Chinese .. )
Diffstat (limited to 'src/graphui/classes/com')
3 files changed, 40 insertions, 49 deletions
diff --git a/src/graphui/classes/com/jogamp/graph/ui/Scene.java b/src/graphui/classes/com/jogamp/graph/ui/Scene.java index 9ebacf2ec..7f47b2d98 100644 --- a/src/graphui/classes/com/jogamp/graph/ui/Scene.java +++ b/src/graphui/classes/com/jogamp/graph/ui/Scene.java @@ -28,7 +28,6 @@ package com.jogamp.graph.ui; import java.io.File; -import java.io.IOException; import java.nio.ByteBuffer; import java.util.ArrayList; import java.util.Arrays; @@ -54,8 +53,6 @@ import com.jogamp.graph.curve.Region; import com.jogamp.graph.curve.opengl.GLRegion; import com.jogamp.graph.curve.opengl.RegionRenderer; import com.jogamp.graph.curve.opengl.RenderState; -import com.jogamp.graph.font.Font; -import com.jogamp.graph.font.FontFactory; import com.jogamp.graph.ui.Shape.Visitor2; import com.jogamp.math.FloatUtil; import com.jogamp.math.Matrix4f; @@ -130,25 +127,6 @@ public final class Scene implements Container, GLEventListener { return FloatUtil.getZBufferEpsilon(zBits, setup.getSceneDist(), setup.getZNear()); } - /** Returns {@link FontFactory#getDefault()} font or null if n/a */ - public static Font getDefaultFont() { - try { - return FontFactory.getDefault().getDefault(); - } catch(final IOException ioe) { - ioe.printStackTrace(); - return null; - } - } - /** Returns the default symbols font or null if n/a */ - public static Font getSymbolsFont() { - try { - return FontFactory.get(FontFactory.SYMBOLS).getDefault(); - } catch(final IOException ioe) { - ioe.printStackTrace(); - return null; - } - } - private static final boolean DEBUG = false; private final List<Shape> shapes = new CopyOnWriteArrayList<Shape>(); diff --git a/src/graphui/classes/com/jogamp/graph/ui/shapes/MediaButton.java b/src/graphui/classes/com/jogamp/graph/ui/shapes/MediaButton.java index bbf1d7b66..54b23ba6a 100644 --- a/src/graphui/classes/com/jogamp/graph/ui/shapes/MediaButton.java +++ b/src/graphui/classes/com/jogamp/graph/ui/shapes/MediaButton.java @@ -39,8 +39,8 @@ import com.jogamp.common.util.InterruptSource; import com.jogamp.graph.curve.Region; import com.jogamp.graph.curve.opengl.RegionRenderer; import com.jogamp.graph.font.Font; +import com.jogamp.graph.font.FontFactory; import com.jogamp.graph.ui.GraphShape; -import com.jogamp.graph.ui.Scene; import com.jogamp.graph.ui.layout.Alignment; import com.jogamp.math.Vec2f; import com.jogamp.math.Vec4f; @@ -78,6 +78,8 @@ public class MediaButton extends TexSeqButton { private static final boolean DEBUG_PGS_POSSZ = false; private boolean verbose = false; + private Font subFont; + private Font subFallbackFont; private final Label subLabel; private final float subZOffset; private boolean subEnabled; @@ -106,18 +108,19 @@ public class MediaButton extends TexSeqButton { private final List<SubtitleEvent> subEventQueue = new ArrayList<SubtitleEvent>(); private final Object subEventLock = new Object(); - /** Constructs a {@link MediaButton} with subtitles disabled. */ + /** Constructs a {@link MediaButton} with {@link FontFactory#getDefaultFont()} for subtitles. */ public MediaButton(final int renderModes, final float width, final float height, final GLMediaPlayer mPlayer) { this(renderModes, width, height, mPlayer, null); } /** - * Constructs a {@link MediaButton} prepared for using subtitles. + * Constructs a {@link MediaButton} prepared for using subtitles * @param renderModes * @param width * @param height * @param mPlayer - * @param subFont text/ASS subtitle font + * @param subFont text/ASS subtitle font, pass {@code null} for {@link FontFactory#getDefaultFont()}. + * {@link FontFactory#getFallbackFont()} is used {@link Font#getBestCoverage(Font, Font, CharSequence) if providing a better coverage} of a Text/ASS subtitle line. * @see #setSubtitleParams(Font, float, float, Alignment) * @see #setSubtitleColor(Vec4f, float) */ @@ -132,23 +135,13 @@ public class MediaButton extends TexSeqButton { mPlayer.setSubtitleEventListener(subEventListener); - final Font f; - if( null != subFont ) { - f = subFont; - subEnabled = true; - } else { - f = Scene.getDefaultFont(); - subEnabled = false; - } + setSubtitleParams(subFont, DEFAULT_ASS_SUB_HEIGHT, DEFAULT_ASS_SUB_POS, DEFAULT_ASS_SUB_ALIGNMENT); + this.subLabel = new Label(renderModes, this.subFont, ""); this.subZOffset = Button.DEFAULT_LABEL_ZOFFSET; - this.subLineHeightPct = DEFAULT_ASS_SUB_HEIGHT; - this.subLineDY = DEFAULT_ASS_SUB_POS; - this.subAlignment = DEFAULT_ASS_SUB_ALIGNMENT; - this.subLabel = new Label(renderModes, f, ""); - this.subLabel.setColor( DEFAULT_ASS_SUB_COLOR ); this.subLabel.moveTo(0, 0, subZOffset); this.subBlend = new Rectangle(renderModes, 1f, 1f, 0f); - this.subBlend.setColor( new Vec4f( 0, 0, 0, DEFAULT_ASS_SUB_BLEND ) ); + setSubtitleColor(DEFAULT_ASS_SUB_COLOR, DEFAULT_ASS_SUB_BLEND); + this.subTexImg = new ImageButton(renderModes, width, height, new ImageSequence(mPlayer.getTextureUnit(), true /* useBuildInTexLookup */)); this.subTexImg.setPerp().setToggleable(false).setDragAndResizeable(false).setInteractive(false); // this.subTexImg.setBorder(0.001f).setBorderColor(1, 1, 0, 1); @@ -157,15 +150,26 @@ public class MediaButton extends TexSeqButton { this.drawLastSub = null; } + /** Toggle enabling subtitle rendering */ + public void setSubtitlesEnabled(final boolean v) { + subEnabled = v; + } + /** - * Sets text/ASS subtitle parameter - * @param subFont text/ASS subtitle font + * Sets text/ASS subtitle parameter, enabling subtitle rendering + * @param subFont text/ASS subtitle font, pass {@code null} for {@link FontFactory#getDefaultFont()} + * {@link FontFactory#getFallbackFont()} is used {@link Font#getBestCoverage(Font, Font, CharSequence) if providing a better coverage} of a Text/ASS subtitle line. * @param subLineHeightPct text/ASS subtitle line height percentage, defaults to {@link #DEFAULT_ASS_SUB_HEIGHT} * @param subLineDY text/ASS y-axis offset to bottom in line-height, defaults to {@link #DEFAULT_ASS_SUB_POS} * @param subAlignment text/ASS subtitle alignment, defaults to {@link #DEFAULT_ASS_SUB_ALIGNMENT} */ public void setSubtitleParams(final Font subFont, final float subLineHeightPct, final float subLineDY, final Alignment subAlignment) { - this.subLabel.setFont(subFont); + if( null != subFont ) { + this.subFont = subFont; + } else { + this.subFont = FontFactory.getDefaultFont(); + } + this.subFallbackFont = FontFactory.getFallbackFont(); this.subLineHeightPct = subLineHeightPct; this.subLineDY = subLineDY; this.subAlignment = subAlignment; @@ -398,6 +402,7 @@ public class MediaButton extends TexSeqButton { } else if( SubtitleEvent.Type.Text == sub.type ) { final SubTextEvent assSub = (SubTextEvent)sub; if( newSub ) { + subLabel.setFont( Font.getBestCoverage(subFont, subFallbackFont, assSub.text) ); subLabel.setText(assSub.text); final AABBox subBox = subLabel.getBounds(gl.getGLProfile()); final float subLineHeight = subBox.getHeight() / assSub.lines; @@ -503,5 +508,4 @@ public class MediaButton extends TexSeqButton { pmv.popMv(); } } - } diff --git a/src/graphui/classes/com/jogamp/graph/ui/widgets/MediaPlayer.java b/src/graphui/classes/com/jogamp/graph/ui/widgets/MediaPlayer.java index d93078288..f434bd0ad 100644 --- a/src/graphui/classes/com/jogamp/graph/ui/widgets/MediaPlayer.java +++ b/src/graphui/classes/com/jogamp/graph/ui/widgets/MediaPlayer.java @@ -38,6 +38,7 @@ import com.jogamp.common.util.InterruptSource; import com.jogamp.graph.curve.Region; import com.jogamp.graph.curve.opengl.GLRegion; import com.jogamp.graph.font.Font; +import com.jogamp.graph.font.FontFactory; import com.jogamp.graph.ui.Group; import com.jogamp.graph.ui.Scene; import com.jogamp.graph.ui.Shape; @@ -106,7 +107,7 @@ public class MediaPlayer extends Widget { { super( new BoxLayout(aratio, 1, Alignment.None) ); - final Font fontInfo = Scene.getDefaultFont(), fontSymbols = Scene.getSymbolsFont(); + final Font fontInfo = FontFactory.getDefaultFont(), fontSymbols = FontFactory.getSymbolsFont(); if( null == fontInfo || null == fontSymbols ) { mButton = null; return; @@ -130,7 +131,7 @@ public class MediaPlayer extends Widget { this.setBorderColor(BorderColor).setBorder(BorderSz); this.setInteractive(true).setFixedARatioResize(true); - mButton = new MediaButton(renderModes, aratio, 1, mPlayer, fontInfo); + mButton = new MediaButton(renderModes, aratio, 1, mPlayer); mButton.setName("mp.mButton").setInteractive(false); mButton.setPerp().setPressedColorMod(1f, 1f, 1f, 0.85f); @@ -170,7 +171,7 @@ public class MediaPlayer extends Widget { audioLabel.setText("audio\n"+mp.getLang(mp.getAID())); subLabel.setText("sub\n"+mp.getLang(mp.getSID())); ctrlSlider.setMinMax(new Vec2f(0, mp.getDuration()), 0); - System.err.println("Init +"+mp.toString()); + System.err.println("Init "+mp.toString()); for(final GLMediaPlayer.Chapter c : mp.getChapters()) { if( DEBUG ) { @@ -623,9 +624,17 @@ public class MediaPlayer extends Widget { ctrlSlider.getKnob().setDraggable(true); } + /** Toggle enabling subtitle rendering */ + public void setSubtitlesEnabled(final boolean v) { + if( null != mButton ) { + mButton.setSubtitlesEnabled(v); + } + } + /** - * Sets text/ASS subtitle parameter - * @param subFont text/ASS subtitle font + * Sets text/ASS subtitle parameter, enabling subtitle rendering + * @param subFont text/ASS subtitle font, pass {@code null} for {@link FontFactory#getDefaultFont()} + * {@link FontFactory#getFallbackFont()} is used {@link Font#getBestCoverage(Font, Font, CharSequence) if providing a better coverage} of a Text/ASS subtitle line. * @param subLineHeightPct text/ASS subtitle line height percentage, defaults to {@link MediaButton#DEFAULT_ASS_SUB_HEIGHT} * @param subLineDY text/ASS y-axis offset to bottom in line-height, defaults to {@link MediaButton#DEFAULT_ASS_SUB_POS} * @param subAlignment text/ASS subtitle alignment, defaults to {@link #DEFAULT_ASS_SUB_ALIGNMENT} |