62 } 63 return map; 64 } 65 66 private void loadEmbeddedFonts() { 67 if (!embeddedFontsLoaded) { 68 FontFactory fontFactory = getFontFactoryFromPipeline(); 69 if (!fontFactory.hasPermission()) { 70 embeddedFontsLoaded = true; 71 return; 72 } 73 Properties map = loadEmbeddedFontDefinitions(); 74 Enumeration<?> names = map.keys(); 75 ClassLoader loader = Thread.currentThread().getContextClassLoader(); 76 while (names.hasMoreElements()) { 77 String n = (String)names.nextElement(); 78 String p = map.getProperty(n); 79 if (p.startsWith("/")) { 80 p = p.substring(1); 81 try (InputStream in = loader.getResourceAsStream(p)) { 82 fontFactory.loadEmbeddedFont(n, in, 0, true); 83 } catch (Exception e) { 84 } 85 } 86 } 87 embeddedFontsLoaded = true; 88 } 89 } 90 91 @Override public Font loadFont(InputStream in, double size) { 92 FontFactory factory = getFontFactoryFromPipeline(); 93 PGFont font = factory.loadEmbeddedFont(null, in, (float)size, true); 94 if (font != null) return createFont(font); 95 return null; 96 } 97 98 @Override public Font loadFont(String path, double size) { 99 FontFactory factory = getFontFactoryFromPipeline(); 100 PGFont font = factory.loadEmbeddedFont(null, path, (float)size, true); 101 if (font != null) return createFont(font); 102 return null; 103 } 104 105 @SuppressWarnings("deprecation") 106 private Font createFont(PGFont font) { 107 return FontHelper.nativeFont(font, 108 font.getName(), 109 font.getFamilyName(), 110 font.getStyleName(), 111 font.getSize()); 112 } 113 114 /** 115 * Gets all the font families installed on the user's system, including any 116 * embedded fonts or SDK fonts. 117 * 118 * @profile common 119 */ 120 @Override public List<String> getFamilies() { 121 loadEmbeddedFonts(); 122 return Arrays.asList(getFontFactoryFromPipeline(). | 62 } 63 return map; 64 } 65 66 private void loadEmbeddedFonts() { 67 if (!embeddedFontsLoaded) { 68 FontFactory fontFactory = getFontFactoryFromPipeline(); 69 if (!fontFactory.hasPermission()) { 70 embeddedFontsLoaded = true; 71 return; 72 } 73 Properties map = loadEmbeddedFontDefinitions(); 74 Enumeration<?> names = map.keys(); 75 ClassLoader loader = Thread.currentThread().getContextClassLoader(); 76 while (names.hasMoreElements()) { 77 String n = (String)names.nextElement(); 78 String p = map.getProperty(n); 79 if (p.startsWith("/")) { 80 p = p.substring(1); 81 try (InputStream in = loader.getResourceAsStream(p)) { 82 fontFactory.loadEmbeddedFont(n, in, 0, true, false); 83 } catch (Exception e) { 84 } 85 } 86 } 87 embeddedFontsLoaded = true; 88 } 89 } 90 91 private Font[] createFonts(PGFont[] fonts) { 92 if (fonts == null || fonts.length == 0) { 93 return null; 94 } 95 Font[] fxFonts = new Font[fonts.length]; 96 for (int i=0; i<fonts.length; i++) { 97 fxFonts[i] = createFont(fonts[i]); 98 } 99 return fxFonts; 100 } 101 102 @Override public Font[] loadFont(InputStream in, 103 double size, 104 boolean loadAll) { 105 106 FontFactory factory = getFontFactoryFromPipeline(); 107 PGFont[] fonts = 108 factory.loadEmbeddedFont(null, in, (float)size, true, loadAll); 109 return createFonts(fonts); 110 } 111 112 @Override public Font[] loadFont(String path, 113 double size, 114 boolean loadAll) { 115 116 FontFactory factory = getFontFactoryFromPipeline(); 117 PGFont[] fonts = 118 factory.loadEmbeddedFont(null, path, (float)size, true, loadAll); 119 return createFonts(fonts); 120 } 121 122 @SuppressWarnings("deprecation") 123 private Font createFont(PGFont font) { 124 return FontHelper.nativeFont(font, 125 font.getName(), 126 font.getFamilyName(), 127 font.getStyleName(), 128 font.getSize()); 129 } 130 131 /** 132 * Gets all the font families installed on the user's system, including any 133 * embedded fonts or SDK fonts. 134 * 135 * @profile common 136 */ 137 @Override public List<String> getFamilies() { 138 loadEmbeddedFonts(); 139 return Arrays.asList(getFontFactoryFromPipeline(). |