Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files
8248802: Add log helper methods to FontUtilities.java
Reviewed-by: clanger, jdv
  • Loading branch information
MBaesken committed Jul 14, 2020
1 parent 13bcda4 commit 7a0914c44c24037e7d5ad42f4d7f619a6c63702f
Show file tree
Hide file tree
Showing 14 changed files with 139 additions and 198 deletions.
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2011, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2011, 2020, 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
@@ -96,8 +96,8 @@ public Font2D registerGenericFont(Font2D f, boolean logicalFont)
// already existing fonts in this list
if (logicalFont || !genericFonts.containsKey(fontName)) {
if (FontUtilities.debugFonts()) {
FontUtilities.getLogger().info("Add to Family "+familyName +
", Font " + fontName + " rank="+rank);
FontUtilities.logInfo("Add to Family " + familyName +
", Font " + fontName + " rank=" + rank);
}
FontFamily family = FontFamily.getFamily(familyName);
if (family == null) {
@@ -83,8 +83,7 @@ public abstract class FontConfiguration {
*/
public FontConfiguration(SunFontManager fm) {
if (FontUtilities.debugFonts()) {
FontUtilities.getLogger()
.info("Creating standard Font Configuration");
FontUtilities.logInfo("Creating standard Font Configuration");
}
if (FontUtilities.debugFonts() && logger == null) {
logger = PlatformLogger.getLogger("sun.awt.FontConfiguration");
@@ -116,8 +115,7 @@ public FontConfiguration(SunFontManager fm,
boolean preferPropFonts) {
fontManager = fm;
if (FontUtilities.debugFonts()) {
FontUtilities.getLogger()
.info("Creating alternate Font Configuration");
FontUtilities.logInfo("Creating alternate Font Configuration");
}
this.preferLocaleFonts = preferLocaleFonts;
this.preferPropFonts = preferPropFonts;
@@ -400,10 +400,8 @@ static CMap createCMap(ByteBuffer buffer, int offset, char[] xlat) {
} else {
subtableLength = buffer.getInt(offset+4) & INTMASK;
}
if (offset+subtableLength > buffer.capacity()) {
if (FontUtilities.isLogging()) {
FontUtilities.getLogger().warning("Cmap subtable overflows buffer.");
}
if (FontUtilities.isLogging() && offset + subtableLength > buffer.capacity()) {
FontUtilities.logWarning("Cmap subtable overflows buffer.");
}
switch (subtableFormat) {
case 0: return new CMapFormat0(buffer, offset);
@@ -422,11 +420,8 @@ private void createUVS(ByteBuffer buffer, int offset) {
int subtableFormat = buffer.getChar(offset);
if (subtableFormat == 14) {
long subtableLength = buffer.getInt(offset + 2) & INTMASK;
if (offset + subtableLength > buffer.capacity()) {
if (FontUtilities.isLogging()) {
FontUtilities.getLogger()
.warning("Cmap UVS subtable overflows buffer.");
}
if (FontUtilities.isLogging() && offset + subtableLength > buffer.capacity()) {
FontUtilities.logWarning("Cmap UVS subtable overflows buffer.");
}
try {
this.uvs = new UVS(buffer, offset);
@@ -223,8 +223,7 @@ public class FileFontStrike extends PhysicalStrike {
useNatives = true;
}
if (FontUtilities.isLogging() && FontUtilities.isWindows) {
FontUtilities.getLogger().info
("Strike for " + fileFont + " at size = " + intPtSize +
FontUtilities.logInfo("Strike for " + fileFont + " at size = " + intPtSize +
" use natives = " + useNatives +
" useJavaRasteriser = " + fileFont.useJavaRasterizer +
" AAHint = " + desc.aaHint +
@@ -319,10 +318,9 @@ long getGlyphImageFromWindows(int glyphCode) {
return ptr;
} else {
if (FontUtilities.isLogging()) {
FontUtilities.getLogger().warning(
"Failed to render glyph using GDI: code=" + glyphCode
+ ", fontFamily=" + family + ", style=" + style
+ ", size=" + size);
FontUtilities.logWarning("Failed to render glyph using GDI: code=" + glyphCode
+ ", fontFamily=" + family + ", style=" + style
+ ", size=" + size);
}
return fileFont.getGlyphImage(pScalerContext, glyphCode);
}
@@ -356,14 +354,13 @@ long getGlyphImagePtr(int glyphCode) {
if (useNatives) {
glyphPtr = getGlyphImageFromNative(glyphCode);
if (glyphPtr == 0L && FontUtilities.isLogging()) {
FontUtilities.getLogger().info
("Strike for " + fileFont +
FontUtilities.logInfo("Strike for " + fileFont +
" at size = " + intPtSize +
" couldn't get native glyph for code = " + glyphCode);
}
} if (glyphPtr == 0L) {
glyphPtr = fileFont.getGlyphImage(pScalerContext,
glyphCode);
}
}
if (glyphPtr == 0L) {
glyphPtr = fileFont.getGlyphImage(pScalerContext, glyphCode);
}
return setCachedGlyphPtr(glyphCode, glyphPtr);
}
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2003, 2006, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2003, 2020, 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
@@ -181,7 +181,7 @@ private boolean preferredWidth(Font2D font) {
Math.abs(Font2D.FWIDTH_NORMAL - familyWidth))
{
if (FontUtilities.debugFonts()) {
FontUtilities.getLogger().info(
FontUtilities.logInfo(
"Found more preferred width. New width = " + newWidth +
" Old width = " + familyWidth + " in font " + font +
" nulling out fonts plain: " + plain + " bold: " + bold +
@@ -191,7 +191,7 @@ private boolean preferredWidth(Font2D font) {
plain = bold = italic = bolditalic = null;
return true;
} else if (FontUtilities.debugFonts()) {
FontUtilities.getLogger().info(
FontUtilities.logInfo(
"Family rejecting font " + font +
" of less preferred width " + newWidth);
}
@@ -208,7 +208,7 @@ private boolean closerWeight(Font2D currFont, Font2D font, int style) {
}

if (FontUtilities.debugFonts()) {
FontUtilities.getLogger().info(
FontUtilities.logInfo(
"New weight for style " + style + ". Curr.font=" + currFont +
" New font="+font+" Curr.weight="+ + currFont.getWeight()+
" New weight="+font.getWeight());
@@ -242,18 +242,17 @@ public void setFont(Font2D font, int style) {
msg = "Request to add " + font +
" with style " + style + " to family " + this;
}
FontUtilities.getLogger().info(msg);
FontUtilities.logInfo(msg);
}
/* Allow a lower-rank font only if its a file font
* from the exact same source as any previous font.
*/
if ((font.getRank() > familyRank) && !isFromSameSource(font)) {
if (FontUtilities.isLogging()) {
FontUtilities.getLogger()
.warning("Rejecting adding " + font +
" of lower rank " + font.getRank() +
" to family " + this +
" of rank " + familyRank);
FontUtilities.logWarning("Rejecting adding " + font +
" of lower rank " + font.getRank() +
" to family " + this +
" of rank " + familyRank);
}
return;
}
@@ -26,10 +26,6 @@
package sun.font;

import java.awt.Font;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.lang.ref.SoftReference;
import java.util.concurrent.ConcurrentHashMap;
import java.security.AccessController;
@@ -112,10 +108,6 @@ public Object run() {
} else if (debugLevel.equals("severe")) {
logger.setLevel(PlatformLogger.Level.SEVERE);
}
}

if (debugFonts) {
logger = PlatformLogger.getLogger("sun.java2d");
logging = logger.isEnabled();
}

@@ -324,6 +316,17 @@ public static boolean debugFonts() {
return debugFonts;
}

public static void logWarning(String s) {
getLogger().warning(s);
}

public static void logInfo(String s) {
getLogger().info(s);
}

public static void logSevere(String s) {
getLogger().severe(s);
}

// The following methods are used by Swing.

@@ -1,5 +1,5 @@
/*
* Copyright (c) 2003, 2014, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2003, 2020, 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
@@ -478,8 +478,7 @@ public StandardGlyphVector layout(Font font, FontRenderContext frc,
if (_gvdata._count < 0) {
gv = new StandardGlyphVector(font, text, offset, count, frc);
if (FontUtilities.debugFonts()) {
FontUtilities.getLogger().warning("OpenType layout failed on font: " +
font);
FontUtilities.logWarning("OpenType layout failed on font: " + font);
}
} else {
gv = _gvdata.createGlyphVector(font, frc, result);

0 comments on commit 7a0914c

Please sign in to comment.