Refactored ListStyleParser css declarations

This commit is contained in:
Georgy Litvinov 2020-01-30 11:50:40 +01:00
parent 5eb9f2186c
commit 66360146d7

View file

@ -97,43 +97,71 @@ public class ListStyleParser extends StyleParser {
StringBuilder buf = new StringBuilder();
Enumeration<String> names = styleNames.keys();
while (names.hasMoreElements()) {
String sDisplayName = names.nextElement();
ListStyle style = (ListStyle) getStyles().getStyleByDisplayName(sDisplayName);
if (!style.isAutomatic()) {
for (int nLevel = 1; nLevel < 10; nLevel++) {
CSVList props = new CSVList(";");
cssList(style, nLevel, props);
buf.append(indent);
buf.append(".listlevel");
buf.append(nLevel);
styleNames.addName(sDisplayName);
buf.append(styleNames.getName(sDisplayName));
buf.append(" {");
buf.append(props.toString());
buf.append("}");
buf.append(prettyPrint ? "\n" : " ");
if (config.listFormatting() == XhtmlConfig.HARD_LABELS) {
// Apply left margin and text indent to the paragraphs contained in
// the list
CSVList parProps = new CSVList(";");
cssListParMargins(style, nLevel, parProps);
if (!parProps.isEmpty()) {
buf.append(indent);
buf.append(".listlevel");
buf.append(nLevel);
styleNames.addName(sDisplayName);
buf.append(styleNames.getName(sDisplayName));
buf.append(" p {");
buf.append(parProps.toString());
buf.append("}");
buf.append(prettyPrint ? "\n" : " ");
}
}
String displayName = names.nextElement();
buf.append(composeDeclaration(displayName));
if (config.listFormatting() == XhtmlConfig.HARD_LABELS) {
buf.append(composeHardDeclaration(displayName));
}
}
return buf.toString();
}
public String composeDeclaration(String displayName) {
StringBuilder buf = new StringBuilder();
ListStyle style = (ListStyle) getStyles().getStyleByDisplayName(displayName);
if (!style.isAutomatic()) {
for (int level = 1; level < 10; level++) {
String selector = composeSelector(displayName, level);
String declarationBlock = composeDeclarationBlock(displayName, level);
if (!selector.isEmpty() && !declarationBlock.isEmpty()) {
buf.append(indent + selector + " {" + declarationBlock + "}" + (prettyPrint ? "\n" : " "));
}
}
}
return buf.toString();
}
}
public String composeHardDeclaration(String displayName) {
StringBuilder buf = new StringBuilder();
ListStyle style = (ListStyle) getStyles().getStyleByDisplayName(displayName);
if (!style.isAutomatic()) {
for (int level = 1; level < 10; level++) {
String declarationBlock = composeHardDeclarationBlock(displayName, level);
String selector = composeHardSelector(displayName, level);
// Apply left margin and text indent to the paragraphs contained in
// the list
if (!declarationBlock.isEmpty() && !selector.isEmpty()) {
buf.append(indent + selector + "{" + declarationBlock + "}" + (prettyPrint ? "\n" : " "));
}
}
}
return buf.toString();
}
private String composeHardSelector(String displayName, int level) {
styleNames.addName(displayName);
return ".listlevel" + level + styleNames.getName(displayName) + " p ";
}
private String composeSelector(String displayName, int level) {
styleNames.addName(displayName);
return ".listlevel" + level + styleNames.getName(displayName);
}
private String composeHardDeclarationBlock(String displayName, int level) {
ListStyle style = (ListStyle) getStyles().getStyleByDisplayName(displayName);
CSVList props = new CSVList(";");
cssListParMargins(style, level, props);
return props.toString();
}
private String composeDeclarationBlock(String displayName, int level) {
ListStyle style = (ListStyle) getStyles().getStyleByDisplayName(displayName);
CSVList props = new CSVList(";");
cssList(style, level, props);
return props.toString();
}
/** Get the family of list styles
* @return the style family