Skip to content

Commit

Permalink
Do not log font is missing more than once
Browse files Browse the repository at this point in the history
  • Loading branch information
danfickle committed May 9, 2021
1 parent 95f2fa5 commit ab48fd0
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ enum LogMessageId0Param implements LogMessageId {

RENDER_BUG_FONT_DIDNT_CONTAIN_EXPECTED_CHARACTER(XRLog.RENDER, "BUG. Font didn't contain expected character."),
RENDER_FONT_LIST_IS_EMPTY(XRLog.RENDER, "Font list is empty."),
RENDER_FONT_IS_NULL(XRLog.RENDER, "Font is null."),

LOAD_UNABLE_TO_DISABLE_XML_EXTERNAL_ENTITIES(XRLog.LOAD, "Unable to disable XML External Entities, which might put you at risk to XXE attacks"),
LOAD_COULD_NOT_SET_VALIDATION_NAMESPACE_FEATURES_FOR_XML_PARSER(XRLog.LOAD, "Could not set validation/namespace features for XML parser, exception thrown."),
Expand Down Expand Up @@ -56,8 +55,7 @@ enum LogMessageId0Param implements LogMessageId {
EXCEPTION_TRIED_TO_OPEN_A_PASSWORD_PROTECTED_DOCUMENT_AS_SRC_FOR_IMG(XRLog.EXCEPTION, "Tried to open a password protected document as src for an img!"),
EXCEPTION_COULD_NOT_READ_PDF_AS_SRC_FOR_IMG(XRLog.EXCEPTION, "Could not read pdf passed as src for img element!"),
EXCEPTION_COULD_NOT_PARSE_DEFAULT_STYLESHEET(XRLog.EXCEPTION, "Could not parse default stylesheet"),
EXCEPTION_SELECTOR_BAD_SIBLING_AXIS(XRLog.EXCEPTION, "Bad sibling axis"),
EXCEPTION_FONT_METRICS_NOT_AVAILABLE(XRLog.EXCEPTION, "Font metrics not available. Probably a bug.");
EXCEPTION_SELECTOR_BAD_SIBLING_AXIS(XRLog.EXCEPTION, "Bad sibling axis");

private final String where;
private final String messageFormat;
Expand Down Expand Up @@ -103,7 +101,7 @@ enum LogMessageId1Param implements LogMessageId {
RENDER_OP_MUST_NOT_BE_USED_BY_FAST_RENDERER(XRLog.RENDER, "{} MUST not be used by the fast renderer. Please consider reporting this bug."),
RENDER_UNKNOWN_PAINT(XRLog.RENDER, "Unknown paint: {}"),
RENDER_USING_CSS_IMPLEMENTATION_FROM(XRLog.RENDER, "Using CSS implementation from: {}"),

RENDER_FONT_IS_NULL(XRLog.RENDER, "Font is null for font-description: {}"),

MATCH_TRYING_TO_APPEND_CONDITIONS_TO_PSEUDO_ELEMENT(XRLog.MATCH, "Trying to append conditions to pseudoElement {}"),
MATCH_MATCHER_CREATED_WITH_SELECTOR(XRLog.MATCH, "Matcher created with {} selectors"),
Expand Down Expand Up @@ -148,6 +146,7 @@ enum LogMessageId1Param implements LogMessageId {
GENERAL_PDF_A_ELEMENT_DOES_NOT_HAVE_OPTION_CHILDREN(XRLog.GENERAL, "A <{}> element does not have <option> children"),
GENERAL_FORCED_OUTPUT_TO_AVOID_INFINITE_LOOP(XRLog.GENERAL, "Forced text ({}) output after trying to move to next line unsuccessfully. Probably a bug."),

EXCEPTION_FONT_METRICS_NOT_AVAILABLE(XRLog.EXCEPTION, "Font metrics not available for font-description: {}"),
EXCEPTION_URI_SYNTAX_WHILE_LOADING_EXTERNAL_SVG_RESOURCE(XRLog.EXCEPTION, "URI syntax exception while loading external svg resource: {}"),
EXCEPTION_SVG_ERROR_HANDLER(XRLog.EXCEPTION, "SVG {}"),
EXCEPTION_PDF_IN_WRITING_METHOD(XRLog.EXCEPTION, "Exception in PDF writing method: {}"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -514,6 +514,13 @@ public static class FontDescription implements MinimalFontDescription {
private PdfBoxRawPDFontMetrics _metrics;
private final FSCacheEx<String, FSCacheValue> _metricsCache;

@Override
public String toString() {
return String.format(
"FontDescription [_style=%s, _weight=%s, _family=%s, _isFromFontFace=%s, _isSubset=%s]",
_style, _weight, _family, _isFromFontFace, _isSubset);
}

/**
* Create a font description from one of the PDF built-in fonts.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,15 @@ public class PdfBoxTextRenderer implements TextRenderer {
private static float TEXT_MEASURING_DELTA = 0.01f;

private BidiReorderer _reorderer;


// These will mean only first missing font/metrics
// is logged but they should have already got a loading warning.
// Quiet the font is missing log message.
private boolean _loggedMissingFont = false;

// Quiet the font metrics not available message.
private boolean _loggedMissingMetrics = false;

public void setup(FontContext context, BidiReorderer reorderer) {
this._reorderer = reorderer;
}
Expand Down Expand Up @@ -75,7 +83,10 @@ public FSFontMetrics getFSFontMetrics(FontContext context, FSFont font, String s
PdfBoxRawPDFontMetrics metrics = des.getFontMetrics();

if (metrics == null) {
XRLog.log(Level.WARNING, LogMessageId.LogMessageId0Param.EXCEPTION_FONT_METRICS_NOT_AVAILABLE);
if (!_loggedMissingMetrics) {
XRLog.log(Level.WARNING, LogMessageId.LogMessageId1Param.EXCEPTION_FONT_METRICS_NOT_AVAILABLE, des);
_loggedMissingMetrics = true;
}
continue;
}

Expand Down Expand Up @@ -337,7 +348,10 @@ public int getWidth(FontContext context, FSFont font, String string) {
result = fd.getFont().getStringWidth(effectiveString) / 1000f * font.getSize2D();
break;
} else {
XRLog.log(Level.WARNING, LogMessageId.LogMessageId0Param.RENDER_FONT_IS_NULL);
if (!_loggedMissingFont) {
XRLog.log(Level.WARNING, LogMessageId.LogMessageId1Param.RENDER_FONT_IS_NULL, fd);
_loggedMissingFont = true;
}
}
}
}
Expand Down

0 comments on commit ab48fd0

Please sign in to comment.