Skip to content
This repository has been archived by the owner on Aug 27, 2022. It is now read-only.

Commit

Permalink
8248802: Add log helper methods to FontUtilities.java
Browse files Browse the repository at this point in the history
Reviewed-by: clanger, jdv
  • Loading branch information
MBaesken committed Jul 14, 2020
1 parent 13bcda4 commit 7a0914c
Show file tree
Hide file tree
Showing 14 changed files with 139 additions and 198 deletions.
6 changes: 3 additions & 3 deletions src/java.desktop/macosx/classes/sun/font/CFontManager.java
@@ -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
Expand Down Expand Up @@ -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) {
Expand Down
6 changes: 2 additions & 4 deletions src/java.desktop/share/classes/sun/awt/FontConfiguration.java
Expand Up @@ -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");
Expand Down Expand Up @@ -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;
Expand Down
13 changes: 4 additions & 9 deletions src/java.desktop/share/classes/sun/font/CMap.java
Expand Up @@ -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);
Expand All @@ -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);
Expand Down
21 changes: 9 additions & 12 deletions src/java.desktop/share/classes/sun/font/FileFontStrike.java
Expand Up @@ -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 +
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);
}
Expand Down
19 changes: 9 additions & 10 deletions src/java.desktop/share/classes/sun/font/FontFamily.java
@@ -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
Expand Down Expand Up @@ -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 +
Expand All @@ -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);
}
Expand All @@ -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());
Expand Down Expand Up @@ -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;
}
Expand Down
19 changes: 11 additions & 8 deletions src/java.desktop/share/classes/sun/font/FontUtilities.java
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
}

Expand Down Expand Up @@ -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.

Expand Down
5 changes: 2 additions & 3 deletions src/java.desktop/share/classes/sun/font/GlyphLayout.java
@@ -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
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 7a0914c

Please sign in to comment.