Skip to content

Commit

Permalink
Improved merging of fonts between inline all styles and specific styles.
Browse files Browse the repository at this point in the history
  • Loading branch information
shannah committed Sep 21, 2017
1 parent 863092a commit 1b2a6d1
Showing 1 changed file with 23 additions and 2 deletions.
25 changes: 23 additions & 2 deletions CodenameOne/src/com/codename1/ui/plaf/StyleParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,9 @@ public StyleInfo setFontSize(String fontSize) {
finfo.setSize(tmp.getSize());
finfo.setSizeUnit(tmp.getSizeUnit());
setFont(finfo.toString());
} else {
finfo.setSizeUnit(UNIT_INHERIT);
setFont(finfo.toString());
}
}

Expand Down Expand Up @@ -829,7 +832,25 @@ static Map<String,String> parseString(Map<String,String> out, String str) {
continue;
}
String key = rule.substring(0, pos);
out.put(key, rule.substring(pos+1));
if ("font".equals(key) && out.containsKey("font")) {
// We may need to merge font rules
FontInfo newFinfo = StyleParser.parseFont(new FontInfo(), rule.substring(pos+1));
FontInfo origFinfo = StyleParser.parseFont(new FontInfo(), out.get("font"));
Float newSize = newFinfo.getSize();
if (newSize != null && newFinfo.getSizeUnit() != StyleParser.UNIT_INHERIT) {
origFinfo.setSize(newSize);
origFinfo.setSizeUnit(newFinfo.getSizeUnit());
}
if (newFinfo.getName() != null) {
origFinfo.setName(newFinfo.getName());
}
if (newFinfo.getFile() != null) {
origFinfo.setFile(newFinfo.getFile());
}
out.put(key, origFinfo.toString());
} else {
out.put(key, rule.substring(pos+1));
}

}
return out;
Expand Down Expand Up @@ -2068,7 +2089,7 @@ public String sizeString(String prefix) {
* @return
*/
public float getSizeInPixels(Style baseStyle) {
if (getSize() == null) {
if (getSize() == null || getSizeUnit() == UNIT_INHERIT) {
Font f = baseStyle.getFont();
if (f == null) f = Font.getDefaultFont();

Expand Down

0 comments on commit 1b2a6d1

Please sign in to comment.