sun.font.Font2DHandle Java Examples
The following examples show how to use
sun.font.Font2DHandle.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Font.java From openjdk-8 with GNU General Public License v2.0 | 6 votes |
private Font(String name, int style, float sizePts, boolean created, Font2DHandle handle) { this(name, style, sizePts); this.createdFont = created; /* Fonts created from a stream will use the same font2D instance * as the parent. * One exception is that if the derived font is requested to be * in a different style, then also check if its a CompositeFont * and if so build a new CompositeFont from components of that style. * CompositeFonts can only be marked as "created" if they are used * to add fall backs to a physical font. And non-composites are * always from "Font.createFont()" and shouldn't get this treatment. */ if (created) { if (handle.font2D instanceof CompositeFont && handle.font2D.getStyle() != style) { FontManager fm = FontManagerFactory.getInstance(); this.font2DHandle = fm.getNewComposite(null, style, handle); } else { this.font2DHandle = handle; } } }
Example #2
Source File: Font.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
private Font(String name, int style, float sizePts, boolean created, Font2DHandle handle) { this(name, style, sizePts); this.createdFont = created; /* Fonts created from a stream will use the same font2D instance * as the parent. * One exception is that if the derived font is requested to be * in a different style, then also check if its a CompositeFont * and if so build a new CompositeFont from components of that style. * CompositeFonts can only be marked as "created" if they are used * to add fall backs to a physical font. And non-composites are * always from "Font.createFont()" and shouldn't get this treatment. */ if (created) { if (handle.font2D instanceof CompositeFont && handle.font2D.getStyle() != style) { FontManager fm = FontManagerFactory.getInstance(); this.font2DHandle = fm.getNewComposite(null, style, handle); } else { this.font2DHandle = handle; } } }
Example #3
Source File: Font.java From jdk8u-jdk with GNU General Public License v2.0 | 6 votes |
private Font(String name, int style, float sizePts, boolean created, Font2DHandle handle) { this(name, style, sizePts); this.createdFont = created; /* Fonts created from a stream will use the same font2D instance * as the parent. * One exception is that if the derived font is requested to be * in a different style, then also check if its a CompositeFont * and if so build a new CompositeFont from components of that style. * CompositeFonts can only be marked as "created" if they are used * to add fall backs to a physical font. And non-composites are * always from "Font.createFont()" and shouldn't get this treatment. */ if (created) { if (handle.font2D instanceof CompositeFont && handle.font2D.getStyle() != style) { FontManager fm = FontManagerFactory.getInstance(); this.font2DHandle = fm.getNewComposite(null, style, handle); } else { this.font2DHandle = handle; } } }
Example #4
Source File: Font.java From Bytecoder with Apache License 2.0 | 6 votes |
private Font(String name, int style, float sizePts, boolean created, Font2DHandle handle) { this(name, style, sizePts); this.createdFont = created; /* Fonts created from a stream will use the same font2D instance * as the parent. * One exception is that if the derived font is requested to be * in a different style, then also check if its a CompositeFont * and if so build a new CompositeFont from components of that style. * CompositeFonts can only be marked as "created" if they are used * to add fall backs to a physical font. And non-composites are * always from "Font.createFont()" and shouldn't get this treatment. */ if (created) { if (handle.font2D instanceof CompositeFont && handle.font2D.getStyle() != style) { FontManager fm = FontManagerFactory.getInstance(); this.font2DHandle = fm.getNewComposite(null, style, handle); } else { this.font2DHandle = handle; } } }
Example #5
Source File: Font.java From Java8CN with Apache License 2.0 | 6 votes |
private Font(String name, int style, float sizePts, boolean created, Font2DHandle handle) { this(name, style, sizePts); this.createdFont = created; /* Fonts created from a stream will use the same font2D instance * as the parent. * One exception is that if the derived font is requested to be * in a different style, then also check if its a CompositeFont * and if so build a new CompositeFont from components of that style. * CompositeFonts can only be marked as "created" if they are used * to add fall backs to a physical font. And non-composites are * always from "Font.createFont()" and shouldn't get this treatment. */ if (created) { if (handle.font2D instanceof CompositeFont && handle.font2D.getStyle() != style) { FontManager fm = FontManagerFactory.getInstance(); this.font2DHandle = fm.getNewComposite(null, style, handle); } else { this.font2DHandle = handle; } } }
Example #6
Source File: Font.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 6 votes |
private Font(String name, int style, float sizePts, boolean created, Font2DHandle handle) { this(name, style, sizePts); this.createdFont = created; /* Fonts created from a stream will use the same font2D instance * as the parent. * One exception is that if the derived font is requested to be * in a different style, then also check if its a CompositeFont * and if so build a new CompositeFont from components of that style. * CompositeFonts can only be marked as "created" if they are used * to add fall backs to a physical font. And non-composites are * always from "Font.createFont()" and shouldn't get this treatment. */ if (created) { if (handle.font2D instanceof CompositeFont && handle.font2D.getStyle() != style) { FontManager fm = FontManagerFactory.getInstance(); this.font2DHandle = fm.getNewComposite(null, style, handle); } else { this.font2DHandle = handle; } } }
Example #7
Source File: Font.java From hottub with GNU General Public License v2.0 | 6 votes |
private Font(String name, int style, float sizePts, boolean created, Font2DHandle handle) { this(name, style, sizePts); this.createdFont = created; /* Fonts created from a stream will use the same font2D instance * as the parent. * One exception is that if the derived font is requested to be * in a different style, then also check if its a CompositeFont * and if so build a new CompositeFont from components of that style. * CompositeFonts can only be marked as "created" if they are used * to add fall backs to a physical font. And non-composites are * always from "Font.createFont()" and shouldn't get this treatment. */ if (created) { if (handle.font2D instanceof CompositeFont && handle.font2D.getStyle() != style) { FontManager fm = FontManagerFactory.getInstance(); this.font2DHandle = fm.getNewComposite(null, style, handle); } else { this.font2DHandle = handle; } } }
Example #8
Source File: Font.java From openjdk-jdk8u with GNU General Public License v2.0 | 6 votes |
private Font(String name, int style, float sizePts, boolean created, Font2DHandle handle) { this(name, style, sizePts); this.createdFont = created; /* Fonts created from a stream will use the same font2D instance * as the parent. * One exception is that if the derived font is requested to be * in a different style, then also check if its a CompositeFont * and if so build a new CompositeFont from components of that style. * CompositeFonts can only be marked as "created" if they are used * to add fall backs to a physical font. And non-composites are * always from "Font.createFont()" and shouldn't get this treatment. */ if (created) { if (handle.font2D instanceof CompositeFont && handle.font2D.getStyle() != style) { FontManager fm = FontManagerFactory.getInstance(); this.font2DHandle = fm.getNewComposite(null, style, handle); } else { this.font2DHandle = handle; } } }
Example #9
Source File: Font.java From openjdk-8-source with GNU General Public License v2.0 | 6 votes |
private Font(String name, int style, float sizePts, boolean created, Font2DHandle handle) { this(name, style, sizePts); this.createdFont = created; /* Fonts created from a stream will use the same font2D instance * as the parent. * One exception is that if the derived font is requested to be * in a different style, then also check if its a CompositeFont * and if so build a new CompositeFont from components of that style. * CompositeFonts can only be marked as "created" if they are used * to add fall backs to a physical font. And non-composites are * always from "Font.createFont()" and shouldn't get this treatment. */ if (created) { if (handle.font2D instanceof CompositeFont && handle.font2D.getStyle() != style) { FontManager fm = FontManagerFactory.getInstance(); this.font2DHandle = fm.getNewComposite(null, style, handle); } else { this.font2DHandle = handle; } } }
Example #10
Source File: Font.java From JDKSourceCode1.8 with MIT License | 6 votes |
private Font(String name, int style, float sizePts, boolean created, Font2DHandle handle) { this(name, style, sizePts); this.createdFont = created; /* Fonts created from a stream will use the same font2D instance * as the parent. * One exception is that if the derived font is requested to be * in a different style, then also check if its a CompositeFont * and if so build a new CompositeFont from components of that style. * CompositeFonts can only be marked as "created" if they are used * to add fall backs to a physical font. And non-composites are * always from "Font.createFont()" and shouldn't get this treatment. */ if (created) { if (handle.font2D instanceof CompositeFont && handle.font2D.getStyle() != style) { FontManager fm = FontManagerFactory.getInstance(); this.font2DHandle = fm.getNewComposite(null, style, handle); } else { this.font2DHandle = handle; } } }
Example #11
Source File: Font.java From jdk8u60 with GNU General Public License v2.0 | 6 votes |
private Font(String name, int style, float sizePts, boolean created, Font2DHandle handle) { this(name, style, sizePts); this.createdFont = created; /* Fonts created from a stream will use the same font2D instance * as the parent. * One exception is that if the derived font is requested to be * in a different style, then also check if its a CompositeFont * and if so build a new CompositeFont from components of that style. * CompositeFonts can only be marked as "created" if they are used * to add fall backs to a physical font. And non-composites are * always from "Font.createFont()" and shouldn't get this treatment. */ if (created) { if (handle.font2D instanceof CompositeFont && handle.font2D.getStyle() != style) { FontManager fm = FontManagerFactory.getInstance(); this.font2DHandle = fm.getNewComposite(null, style, handle); } else { this.font2DHandle = handle; } } }
Example #12
Source File: Font.java From jdk1.8-source-analysis with Apache License 2.0 | 6 votes |
private Font(String name, int style, float sizePts, boolean created, Font2DHandle handle) { this(name, style, sizePts); this.createdFont = created; /* Fonts created from a stream will use the same font2D instance * as the parent. * One exception is that if the derived font is requested to be * in a different style, then also check if its a CompositeFont * and if so build a new CompositeFont from components of that style. * CompositeFonts can only be marked as "created" if they are used * to add fall backs to a physical font. And non-composites are * always from "Font.createFont()" and shouldn't get this treatment. */ if (created) { if (handle.font2D instanceof CompositeFont && handle.font2D.getStyle() != style) { FontManager fm = FontManagerFactory.getInstance(); this.font2DHandle = fm.getNewComposite(null, style, handle); } else { this.font2DHandle = handle; } } }
Example #13
Source File: Font.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 6 votes |
private Font(String name, int style, float sizePts, boolean created, Font2DHandle handle) { this(name, style, sizePts); this.createdFont = created; /* Fonts created from a stream will use the same font2D instance * as the parent. * One exception is that if the derived font is requested to be * in a different style, then also check if its a CompositeFont * and if so build a new CompositeFont from components of that style. * CompositeFonts can only be marked as "created" if they are used * to add fall backs to a physical font. And non-composites are * always from "Font.createFont()" and shouldn't get this treatment. */ if (created) { if (handle.font2D instanceof CompositeFont && handle.font2D.getStyle() != style) { FontManager fm = FontManagerFactory.getInstance(); this.font2DHandle = fm.getNewComposite(null, style, handle); } else { this.font2DHandle = handle; } } }
Example #14
Source File: Font.java From TencentKona-8 with GNU General Public License v2.0 | 6 votes |
private Font(String name, int style, float sizePts, boolean created, Font2DHandle handle) { this(name, style, sizePts); this.createdFont = created; /* Fonts created from a stream will use the same font2D instance * as the parent. * One exception is that if the derived font is requested to be * in a different style, then also check if its a CompositeFont * and if so build a new CompositeFont from components of that style. * CompositeFonts can only be marked as "created" if they are used * to add fall backs to a physical font. And non-composites are * always from "Font.createFont()" and shouldn't get this treatment. */ if (created) { if (handle.font2D instanceof CompositeFont && handle.font2D.getStyle() != style) { FontManager fm = FontManagerFactory.getInstance(); this.font2DHandle = fm.getNewComposite(null, style, handle); } else { this.font2DHandle = handle; } } }
Example #15
Source File: Font.java From jdk8u-jdk with GNU General Public License v2.0 | 6 votes |
private Font(String name, int style, float sizePts, boolean created, Font2DHandle handle) { this(name, style, sizePts); this.createdFont = created; /* Fonts created from a stream will use the same font2D instance * as the parent. * One exception is that if the derived font is requested to be * in a different style, then also check if its a CompositeFont * and if so build a new CompositeFont from components of that style. * CompositeFonts can only be marked as "created" if they are used * to add fall backs to a physical font. And non-composites are * always from "Font.createFont()" and shouldn't get this treatment. */ if (created) { if (handle.font2D instanceof CompositeFont && handle.font2D.getStyle() != style) { FontManager fm = FontManagerFactory.getInstance(); this.font2DHandle = fm.getNewComposite(null, style, handle); } else { this.font2DHandle = handle; } } }
Example #16
Source File: Font.java From dragonwell8_jdk with GNU General Public License v2.0 | 6 votes |
private Font(String name, int style, float sizePts, boolean created, Font2DHandle handle) { this(name, style, sizePts); this.createdFont = created; /* Fonts created from a stream will use the same font2D instance * as the parent. * One exception is that if the derived font is requested to be * in a different style, then also check if its a CompositeFont * and if so build a new CompositeFont from components of that style. * CompositeFonts can only be marked as "created" if they are used * to add fall backs to a physical font. And non-composites are * always from "Font.createFont()" and shouldn't get this treatment. */ if (created) { if (handle.font2D instanceof CompositeFont && handle.font2D.getStyle() != style) { FontManager fm = FontManagerFactory.getInstance(); this.font2DHandle = fm.getNewComposite(null, style, handle); } else { this.font2DHandle = handle; } } }
Example #17
Source File: Font.java From jdk8u_jdk with GNU General Public License v2.0 | 6 votes |
private Font(String name, int style, float sizePts, boolean created, Font2DHandle handle) { this(name, style, sizePts); this.createdFont = created; /* Fonts created from a stream will use the same font2D instance * as the parent. * One exception is that if the derived font is requested to be * in a different style, then also check if its a CompositeFont * and if so build a new CompositeFont from components of that style. * CompositeFonts can only be marked as "created" if they are used * to add fall backs to a physical font. And non-composites are * always from "Font.createFont()" and shouldn't get this treatment. */ if (created) { if (handle.font2D instanceof CompositeFont && handle.font2D.getStyle() != style) { FontManager fm = FontManagerFactory.getInstance(); this.font2DHandle = fm.getNewComposite(null, style, handle); } else { this.font2DHandle = handle; } } }
Example #18
Source File: Font.java From jdk-1.7-annotated with Apache License 2.0 | 6 votes |
private Font(String name, int style, float sizePts, boolean created, Font2DHandle handle) { this(name, style, sizePts); this.createdFont = created; /* Fonts created from a stream will use the same font2D instance * as the parent. * One exception is that if the derived font is requested to be * in a different style, then also check if its a CompositeFont * and if so build a new CompositeFont from components of that style. * CompositeFonts can only be marked as "created" if they are used * to add fall backs to a physical font. And non-composites are * always from "Font.createFont()" and shouldn't get this treatment. */ if (created) { if (handle.font2D instanceof CompositeFont && handle.font2D.getStyle() != style) { FontManager fm = FontManagerFactory.getInstance(); this.font2DHandle = fm.getNewComposite(null, style, handle); } else { this.font2DHandle = handle; } } }
Example #19
Source File: Font.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
private Font(AttributeValues values, String oldName, int oldStyle, boolean created, Font2DHandle handle) { this.createdFont = created; if (created) { this.font2DHandle = handle; String newName = null; if (oldName != null) { newName = values.getFamily(); if (oldName.equals(newName)) newName = null; } int newStyle = 0; if (oldStyle == -1) { newStyle = -1; } else { if (values.getWeight() >= 2f) newStyle = BOLD; if (values.getPosture() >= .2f) newStyle |= ITALIC; if (oldStyle == newStyle) newStyle = -1; } if (handle.font2D instanceof CompositeFont) { if (newStyle != -1 || newName != null) { FontManager fm = FontManagerFactory.getInstance(); this.font2DHandle = fm.getNewComposite(newName, newStyle, handle); } } else if (newName != null) { this.createdFont = false; this.font2DHandle = null; } } initFromValues(values); }
Example #20
Source File: FontDisposeTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
public static void main(String[] args) throws Exception { // The bug only happens with Type 1 fonts. The Ghostscript font files // should be commonly available. From distro pacakge or // ftp://ftp.gnu.org/gnu/ghostscript/gnu-gs-fonts-other-6.0.tar.gz // Pass pfa/pfb font file as argument String path = args[0]; // Load InputStream stream = new FileInputStream(path); Font font = Font.createFont(Font.TYPE1_FONT,stream); // Ensure native bits have been generated BufferedImage img = new BufferedImage(100,100, BufferedImage.TYPE_INT_ARGB); Graphics2D g2d = img.createGraphics(); FontRenderContext frc = g2d.getFontRenderContext(); font.getLineMetrics("derp",frc); // Force disposal - // System.gc() is not sufficient. Field font2DHandleField = Font.class.getDeclaredField("font2DHandle"); font2DHandleField.setAccessible(true); sun.font.Font2DHandle font2DHandle = (sun.font.Font2DHandle)font2DHandleField.get(font); sun.font.Font2D font2D = font2DHandle.font2D; sun.font.Type1Font type1Font = (sun.font.Type1Font)font2D; Method getScalerMethod = sun.font.Type1Font.class.getDeclaredMethod("getScaler"); getScalerMethod.setAccessible(true); sun.font.FontScaler scaler = (sun.font.FontScaler)getScalerMethod.invoke(type1Font); // dispose should not crash due to double free scaler.dispose(); }
Example #21
Source File: Font.java From jdk-1.7-annotated with Apache License 2.0 | 5 votes |
private Font(AttributeValues values, String oldName, int oldStyle, boolean created, Font2DHandle handle) { this.createdFont = created; if (created) { this.font2DHandle = handle; String newName = null; if (oldName != null) { newName = values.getFamily(); if (oldName.equals(newName)) newName = null; } int newStyle = 0; if (oldStyle == -1) { newStyle = -1; } else { if (values.getWeight() >= 2f) newStyle = BOLD; if (values.getPosture() >= .2f) newStyle |= ITALIC; if (oldStyle == newStyle) newStyle = -1; } if (handle.font2D instanceof CompositeFont) { if (newStyle != -1 || newName != null) { FontManager fm = FontManagerFactory.getInstance(); this.font2DHandle = fm.getNewComposite(newName, newStyle, handle); } } else if (newName != null) { this.createdFont = false; this.font2DHandle = null; } } initFromValues(values); }
Example #22
Source File: Font.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
private Font(AttributeValues values, String oldName, int oldStyle, boolean created, Font2DHandle handle) { this.createdFont = created; if (created) { this.font2DHandle = handle; String newName = null; if (oldName != null) { newName = values.getFamily(); if (oldName.equals(newName)) newName = null; } int newStyle = 0; if (oldStyle == -1) { newStyle = -1; } else { if (values.getWeight() >= 2f) newStyle = BOLD; if (values.getPosture() >= .2f) newStyle |= ITALIC; if (oldStyle == newStyle) newStyle = -1; } if (handle.font2D instanceof CompositeFont) { if (newStyle != -1 || newName != null) { FontManager fm = FontManagerFactory.getInstance(); this.font2DHandle = fm.getNewComposite(newName, newStyle, handle); } } else if (newName != null) { this.createdFont = false; this.font2DHandle = null; } } initFromValues(values); }
Example #23
Source File: Font.java From Java8CN with Apache License 2.0 | 5 votes |
private Font(AttributeValues values, String oldName, int oldStyle, boolean created, Font2DHandle handle) { this.createdFont = created; if (created) { this.font2DHandle = handle; String newName = null; if (oldName != null) { newName = values.getFamily(); if (oldName.equals(newName)) newName = null; } int newStyle = 0; if (oldStyle == -1) { newStyle = -1; } else { if (values.getWeight() >= 2f) newStyle = BOLD; if (values.getPosture() >= .2f) newStyle |= ITALIC; if (oldStyle == newStyle) newStyle = -1; } if (handle.font2D instanceof CompositeFont) { if (newStyle != -1 || newName != null) { FontManager fm = FontManagerFactory.getInstance(); this.font2DHandle = fm.getNewComposite(newName, newStyle, handle); } } else if (newName != null) { this.createdFont = false; this.font2DHandle = null; } } initFromValues(values); }
Example #24
Source File: Font.java From hottub with GNU General Public License v2.0 | 5 votes |
private Font(AttributeValues values, String oldName, int oldStyle, boolean created, Font2DHandle handle) { this.createdFont = created; if (created) { this.font2DHandle = handle; String newName = null; if (oldName != null) { newName = values.getFamily(); if (oldName.equals(newName)) newName = null; } int newStyle = 0; if (oldStyle == -1) { newStyle = -1; } else { if (values.getWeight() >= 2f) newStyle = BOLD; if (values.getPosture() >= .2f) newStyle |= ITALIC; if (oldStyle == newStyle) newStyle = -1; } if (handle.font2D instanceof CompositeFont) { if (newStyle != -1 || newName != null) { FontManager fm = FontManagerFactory.getInstance(); this.font2DHandle = fm.getNewComposite(newName, newStyle, handle); } } else if (newName != null) { this.createdFont = false; this.font2DHandle = null; } } initFromValues(values); }
Example #25
Source File: Font.java From openjdk-8-source with GNU General Public License v2.0 | 5 votes |
private Font(AttributeValues values, String oldName, int oldStyle, boolean created, Font2DHandle handle) { this.createdFont = created; if (created) { this.font2DHandle = handle; String newName = null; if (oldName != null) { newName = values.getFamily(); if (oldName.equals(newName)) newName = null; } int newStyle = 0; if (oldStyle == -1) { newStyle = -1; } else { if (values.getWeight() >= 2f) newStyle = BOLD; if (values.getPosture() >= .2f) newStyle |= ITALIC; if (oldStyle == newStyle) newStyle = -1; } if (handle.font2D instanceof CompositeFont) { if (newStyle != -1 || newName != null) { FontManager fm = FontManagerFactory.getInstance(); this.font2DHandle = fm.getNewComposite(newName, newStyle, handle); } } else if (newName != null) { this.createdFont = false; this.font2DHandle = null; } } initFromValues(values); }
Example #26
Source File: FontDisposeTest.java From jdk8u_jdk with GNU General Public License v2.0 | 5 votes |
public static void main(String[] args) throws Exception { // The bug only happens with Type 1 fonts. The Ghostscript font files // should be commonly available. From distro pacakge or // ftp://ftp.gnu.org/gnu/ghostscript/gnu-gs-fonts-other-6.0.tar.gz // Pass pfa/pfb font file as argument String path = args[0]; // Load InputStream stream = new FileInputStream(path); Font font = Font.createFont(Font.TYPE1_FONT,stream); // Ensure native bits have been generated BufferedImage img = new BufferedImage(100,100, BufferedImage.TYPE_INT_ARGB); Graphics2D g2d = img.createGraphics(); FontRenderContext frc = g2d.getFontRenderContext(); font.getLineMetrics("derp",frc); // Force disposal - // System.gc() is not sufficient. Field font2DHandleField = Font.class.getDeclaredField("font2DHandle"); font2DHandleField.setAccessible(true); sun.font.Font2DHandle font2DHandle = (sun.font.Font2DHandle)font2DHandleField.get(font); sun.font.Font2D font2D = font2DHandle.font2D; sun.font.Type1Font type1Font = (sun.font.Type1Font)font2D; Method getScalerMethod = sun.font.Type1Font.class.getDeclaredMethod("getScaler"); getScalerMethod.setAccessible(true); sun.font.FontScaler scaler = (sun.font.FontScaler)getScalerMethod.invoke(type1Font); // dispose should not crash due to double free scaler.dispose(); }
Example #27
Source File: Font.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 5 votes |
private Font(AttributeValues values, String oldName, int oldStyle, boolean created, Font2DHandle handle) { this.createdFont = created; if (created) { this.font2DHandle = handle; String newName = null; if (oldName != null) { newName = values.getFamily(); if (oldName.equals(newName)) newName = null; } int newStyle = 0; if (oldStyle == -1) { newStyle = -1; } else { if (values.getWeight() >= 2f) newStyle = BOLD; if (values.getPosture() >= .2f) newStyle |= ITALIC; if (oldStyle == newStyle) newStyle = -1; } if (handle.font2D instanceof CompositeFont) { if (newStyle != -1 || newName != null) { FontManager fm = FontManagerFactory.getInstance(); this.font2DHandle = fm.getNewComposite(newName, newStyle, handle); } } else if (newName != null) { this.createdFont = false; this.font2DHandle = null; } } initFromValues(values); }
Example #28
Source File: Font.java From openjdk-8 with GNU General Public License v2.0 | 5 votes |
private Font(AttributeValues values, String oldName, int oldStyle, boolean created, Font2DHandle handle) { this.createdFont = created; if (created) { this.font2DHandle = handle; String newName = null; if (oldName != null) { newName = values.getFamily(); if (oldName.equals(newName)) newName = null; } int newStyle = 0; if (oldStyle == -1) { newStyle = -1; } else { if (values.getWeight() >= 2f) newStyle = BOLD; if (values.getPosture() >= .2f) newStyle |= ITALIC; if (oldStyle == newStyle) newStyle = -1; } if (handle.font2D instanceof CompositeFont) { if (newStyle != -1 || newName != null) { FontManager fm = FontManagerFactory.getInstance(); this.font2DHandle = fm.getNewComposite(newName, newStyle, handle); } } else if (newName != null) { this.createdFont = false; this.font2DHandle = null; } } initFromValues(values); }
Example #29
Source File: Font.java From jdk8u_jdk with GNU General Public License v2.0 | 5 votes |
private Font(AttributeValues values, String oldName, int oldStyle, boolean created, Font2DHandle handle) { this.createdFont = created; if (created) { this.font2DHandle = handle; String newName = null; if (oldName != null) { newName = values.getFamily(); if (oldName.equals(newName)) newName = null; } int newStyle = 0; if (oldStyle == -1) { newStyle = -1; } else { if (values.getWeight() >= 2f) newStyle = BOLD; if (values.getPosture() >= .2f) newStyle |= ITALIC; if (oldStyle == newStyle) newStyle = -1; } if (handle.font2D instanceof CompositeFont) { if (newStyle != -1 || newName != null) { FontManager fm = FontManagerFactory.getInstance(); this.font2DHandle = fm.getNewComposite(newName, newStyle, handle); } } else if (newName != null) { this.createdFont = false; this.font2DHandle = null; } } initFromValues(values); }
Example #30
Source File: FontDisposeTest.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
public static void main(String[] args) throws Exception { // The bug only happens with Type 1 fonts. The Ghostscript font files // should be commonly available. From distro pacakge or // ftp://ftp.gnu.org/gnu/ghostscript/gnu-gs-fonts-other-6.0.tar.gz // Pass pfa/pfb font file as argument String path = args[0]; // Load InputStream stream = new FileInputStream(path); Font font = Font.createFont(Font.TYPE1_FONT,stream); // Ensure native bits have been generated BufferedImage img = new BufferedImage(100,100, BufferedImage.TYPE_INT_ARGB); Graphics2D g2d = img.createGraphics(); FontRenderContext frc = g2d.getFontRenderContext(); font.getLineMetrics("derp",frc); // Force disposal - // System.gc() is not sufficient. Field font2DHandleField = Font.class.getDeclaredField("font2DHandle"); font2DHandleField.setAccessible(true); sun.font.Font2DHandle font2DHandle = (sun.font.Font2DHandle)font2DHandleField.get(font); sun.font.Font2D font2D = font2DHandle.font2D; sun.font.Type1Font type1Font = (sun.font.Type1Font)font2D; Method getScalerMethod = sun.font.Type1Font.class.getDeclaredMethod("getScaler"); getScalerMethod.setAccessible(true); sun.font.FontScaler scaler = (sun.font.FontScaler)getScalerMethod.invoke(type1Font); // dispose should not crash due to double free scaler.dispose(); }