Skip to content

Commit 1b2a6d1

Browse files
committed
Improved merging of fonts between inline all styles and specific styles.
1 parent 863092a commit 1b2a6d1

File tree

1 file changed

+23
-2
lines changed

1 file changed

+23
-2
lines changed

CodenameOne/src/com/codename1/ui/plaf/StyleParser.java

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,9 @@ public StyleInfo setFontSize(String fontSize) {
378378
finfo.setSize(tmp.getSize());
379379
finfo.setSizeUnit(tmp.getSizeUnit());
380380
setFont(finfo.toString());
381+
} else {
382+
finfo.setSizeUnit(UNIT_INHERIT);
383+
setFont(finfo.toString());
381384
}
382385
}
383386

@@ -829,7 +832,25 @@ static Map<String,String> parseString(Map<String,String> out, String str) {
829832
continue;
830833
}
831834
String key = rule.substring(0, pos);
832-
out.put(key, rule.substring(pos+1));
835+
if ("font".equals(key) && out.containsKey("font")) {
836+
// We may need to merge font rules
837+
FontInfo newFinfo = StyleParser.parseFont(new FontInfo(), rule.substring(pos+1));
838+
FontInfo origFinfo = StyleParser.parseFont(new FontInfo(), out.get("font"));
839+
Float newSize = newFinfo.getSize();
840+
if (newSize != null && newFinfo.getSizeUnit() != StyleParser.UNIT_INHERIT) {
841+
origFinfo.setSize(newSize);
842+
origFinfo.setSizeUnit(newFinfo.getSizeUnit());
843+
}
844+
if (newFinfo.getName() != null) {
845+
origFinfo.setName(newFinfo.getName());
846+
}
847+
if (newFinfo.getFile() != null) {
848+
origFinfo.setFile(newFinfo.getFile());
849+
}
850+
out.put(key, origFinfo.toString());
851+
} else {
852+
out.put(key, rule.substring(pos+1));
853+
}
833854

834855
}
835856
return out;
@@ -2068,7 +2089,7 @@ public String sizeString(String prefix) {
20682089
* @return
20692090
*/
20702091
public float getSizeInPixels(Style baseStyle) {
2071-
if (getSize() == null) {
2092+
if (getSize() == null || getSizeUnit() == UNIT_INHERIT) {
20722093
Font f = baseStyle.getFont();
20732094
if (f == null) f = Font.getDefaultFont();
20742095

0 commit comments

Comments
 (0)