Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cached effective rPr from pRPr #407

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 27 additions & 5 deletions docx4j-core/src/main/java/org/docx4j/fonts/RunFontSelector.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import org.w3c.dom.Element;

import java.awt.font.NumericShaper;
import java.util.HashMap;
import java.util.concurrent.ExecutionException;

/**
Expand Down Expand Up @@ -67,7 +68,9 @@ public class RunFontSelector {

private WordprocessingMLPackage wordMLPackage;
private RunFontCharacterVisitor vis;


private java.util.Map<String, RPr> resolvedEffectiveStyleRPrFromPStyle = new HashMap<String, RPr>();

private RunFontActionType outputType;
public enum RunFontActionType {
XSL_FO,
Expand Down Expand Up @@ -366,9 +369,16 @@ public Object fontSelector(PPr pPr, RPr rPr, String text) {


// now apply the direct rPr
rPr = propertyResolver.getEffectiveRPrUsingPStyleRPr(rPr, pRPr);

// cache effective rPr
String effectiveRPrKey = buildEffectiveRPrKey(rPr, pRPr);
if (resolvedEffectiveStyleRPrFromPStyle.get(effectiveRPrKey) != null) {
rPr = resolvedEffectiveStyleRPrFromPStyle.get(effectiveRPrKey);
} else {
rPr = propertyResolver.getEffectiveRPrUsingPStyleRPr(rPr, pRPr);
resolvedEffectiveStyleRPrFromPStyle.put(effectiveRPrKey, rPr);
}
// TODO use effective rPr, but don't inherit theme val,
// TODO, add cache?

if(log.isDebugEnabled()) {
log.debug("effective\n" + XmlUtils.marshaltoString(rPr));
Expand Down Expand Up @@ -588,8 +598,20 @@ && getThemePart()!=null) {
return unicodeRangeToFont(text, hint, langEastAsia,
eastAsia, ascii, hAnsi );
}

private boolean contains(String langEastAsia, String lang) {

private String buildEffectiveRPrKey(RPr rPr, RPr pRPr) {
String left = "";
String right = "";
if (rPr != null && pRPr.getRStyle() != null) {
left = rPr.getRStyle().getVal();
}
if (pRPr != null && pRPr.getRStyle() != null) {
right = pRPr.getRStyle().getVal();
}
return new StringBuilder().append(left).append("_").append(right).toString();
}

private boolean contains(String langEastAsia, String lang) {

// eg <w:lang w:eastAsia="zh-CN" .. />
if (langEastAsia==null) return false;
Expand Down