From 7da7164667f227cb5c59c41d737b22ca77eed994 Mon Sep 17 00:00:00 2001
From: linyuxuan <linyuxuan@kylinos.cn>
Date: Fri, 5 Jan 2024 10:39:21 +0800
Subject: [PATCH 4/4] Enables glyphs fallback for FileFont

Makes the FileFont class implements the FontSubstitution interface,
so that it can use alternate fonts when rendering.
---
 .../share/classes/sun/font/FileFont.java        | 17 +++++++++++++++--
 1 file changed, 15 insertions(+), 2 deletions(-)

diff --git a/src/java.desktop/share/classes/sun/font/FileFont.java b/src/java.desktop/share/classes/sun/font/FileFont.java
index da5874518fa..2dbf9714ab0 100644
--- a/src/java.desktop/share/classes/sun/font/FileFont.java
+++ b/src/java.desktop/share/classes/sun/font/FileFont.java
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2003, 2021, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 2023, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -41,7 +41,7 @@
 import java.security.PrivilegedActionException;
 import java.security.PrivilegedExceptionAction;
 
-public abstract class FileFont extends PhysicalFont {
+public abstract class FileFont extends PhysicalFont implements FontSubstitution {
 
     protected boolean useJavaRasterizer = true;
 
@@ -78,6 +78,8 @@ public abstract class FileFont extends PhysicalFont {
      */
     protected NativeFont[] nativeFonts;
     protected char[] glyphToCharMap;
+
+    protected CompositeFont compFont;
     /*
      * @throws FontFormatException if the font can't be opened
      */
@@ -287,6 +289,17 @@ public Object run() {
         }
     }
 
+    @Override
+    public CompositeFont getCompositeFont2D() {
+        if (compFont == null) {
+            SunFontManager fm = SunFontManager.getInstance();
+            CompositeFont fallbackFont =
+                    (CompositeFont)fm.getFontFromFontConfiguration(familyName, style);
+            compFont = new CompositeFont(this, fallbackFont);
+        }
+        return compFont;
+    }
+
     @SuppressWarnings("removal")
     protected String getPublicFileName() {
         SecurityManager sm = System.getSecurityManager();
-- 
2.39.2

