From 79784f0f7c7d646271815e851476f9e7eb5abc97 Mon Sep 17 00:00:00 2001 From: Georgy Litvinov Date: Wed, 29 Jan 2020 17:25:33 +0100 Subject: [PATCH] Method addExportName split in getName and addName --- .../util/ExportNameCollection.java | 7 +-- .../java/writer2latex/xhtml/Converter.java | 14 +++-- .../xhtml/style/FrameStyleParser.java | 3 +- .../xhtml/style/HeadingStyleParser.java | 62 ++++++++++--------- .../xhtml/style/ListStyleParser.java | 10 +-- .../xhtml/style/PageStyleParser.java | 6 +- .../xhtml/style/PresentationStyleParser.java | 7 ++- .../style/StyleWithPropertiesParser.java | 6 +- .../xhtml/style/TextStyleParser.java | 8 ++- 9 files changed, 71 insertions(+), 52 deletions(-) diff --git a/src/main/java/writer2latex/util/ExportNameCollection.java b/src/main/java/writer2latex/util/ExportNameCollection.java index 8f985c9..a7fb20f 100644 --- a/src/main/java/writer2latex/util/ExportNameCollection.java +++ b/src/main/java/writer2latex/util/ExportNameCollection.java @@ -109,10 +109,9 @@ public class ExportNameCollection{ } } - public String addToExport(String sName) { - // add the name, if it does not exist - if (!containsName(sName)) { addName(sName); } - return sPrefix + exportNames.get(sName); + public String getName(String name) { + return sPrefix + exportNames.get(name); + } public boolean containsName(String sName) { diff --git a/src/main/java/writer2latex/xhtml/Converter.java b/src/main/java/writer2latex/xhtml/Converter.java index a77de02..0be2504 100644 --- a/src/main/java/writer2latex/xhtml/Converter.java +++ b/src/main/java/writer2latex/xhtml/Converter.java @@ -328,12 +328,14 @@ public class Converter extends BasicConverter { Integer targetIndex = targets.get(ld.sId); if (targetIndex!=null) { int nTargetIndex = targetIndex.intValue(); + targetNames.addName(ld.sId); if (nTargetIndex == ld.nIndex) { // same file - ld.element.setAttribute("href","#"+targetNames.addToExport(ld.sId)); + + ld.element.setAttribute("href","#"+targetNames.getName(ld.sId)); } else { - ld.element.setAttribute("href",getOutFileName(nTargetIndex,true) - +"#"+targetNames.addToExport(ld.sId)); + ld.element.setAttribute("href",getOutFileName(nTargetIndex,true) + +"#"+targetNames.getName(ld.sId)); } } } @@ -813,14 +815,16 @@ public class Converter extends BasicConverter { // create a target public Element createTarget(String sId) { Element a = htmlDOM.createElement("a"); - a.setAttribute("id",targetNames.addToExport(sId)); + targetNames.addName(sId); + a.setAttribute("id",targetNames.getName(sId)); targets.put(sId, new Integer(outFileIndex)); return a; } // put a target id on an existing element public void addTarget(Element node,String sId) { - node.setAttribute("id",targetNames.addToExport(sId)); + targetNames.addName(sId); + node.setAttribute("id",targetNames.getName(sId)); targets.put(sId, new Integer(outFileIndex)); } diff --git a/src/main/java/writer2latex/xhtml/style/FrameStyleParser.java b/src/main/java/writer2latex/xhtml/style/FrameStyleParser.java index bb7284b..5ac4872 100644 --- a/src/main/java/writer2latex/xhtml/style/FrameStyleParser.java +++ b/src/main/java/writer2latex/xhtml/style/FrameStyleParser.java @@ -80,7 +80,8 @@ public class FrameStyleParser extends StyleWithPropertiesParser { buf.append(getStyleTag()); buf.append("."); buf.append(getClassNamePrefix()); - buf.append(styleNames.addToExport(sDisplayName)); + styleNames.addName(sDisplayName); + buf.append(styleNames.getName(sDisplayName)); buf.append(" p {"); buf.append(props.toString()); buf.append("}"); diff --git a/src/main/java/writer2latex/xhtml/style/HeadingStyleParser.java b/src/main/java/writer2latex/xhtml/style/HeadingStyleParser.java index 5803817..081ff3d 100644 --- a/src/main/java/writer2latex/xhtml/style/HeadingStyleParser.java +++ b/src/main/java/writer2latex/xhtml/style/HeadingStyleParser.java @@ -85,7 +85,8 @@ public class HeadingStyleParser extends StyleParser { result.append("h"); result.append(i); result.append("."); - result.append(styleNames.addToExport(sDisplayName)); + styleNames.addName(sDisplayName); + result.append(styleNames.getName(sDisplayName)); result.append(" {"); result.append(props.toString()); result.append("}"); @@ -107,34 +108,37 @@ public class HeadingStyleParser extends StyleParser { * @param info add style information to this StyleInfo */ public void applyStyle(int nLevel, String sStyleName, StyleInfo info) { - StyleWithProperties style = (StyleWithProperties) getStyles().getStyle(sStyleName); - if (style!=null) { - if (config.multilingual()) { applyLang(style,info); } - applyDirection(style,info); - if (style.isAutomatic()) { - // Apply parent style + hard formatting - applyStyle(nLevel, style.getParentName(),info); - if (bConvertHard) { getParSc().applyProperties(style,info.props,false); } - } - else { - String sDisplayName = style.getDisplayName(); - if (styleMap.contains(sDisplayName)) { - // Apply attributes as specified in style map from user - XhtmlStyleMapItem map = styleMap.get(sDisplayName); - info.sTagName = map.sBlockElement; - if (!"(none)".equals(map.sBlockCss)) { - info.sClass = map.sBlockCss; - } - } - else if (style!=ofr.getHeadingStyle(nLevel)) { - // This is not the main style for this level, add class and remember - info.sClass = styleNames.addToExport(sDisplayName); - if (1<=nLevel && nLevel<=6) { - otherLevelStyles.get(nLevel).add(sDisplayName); - } - } - } - } + StyleWithProperties style = (StyleWithProperties) getStyles().getStyle(sStyleName); + if (style != null) { + if (config.multilingual()) { + applyLang(style, info); + } + applyDirection(style, info); + if (style.isAutomatic()) { + // Apply parent style + hard formatting + applyStyle(nLevel, style.getParentName(), info); + if (bConvertHard) { + getParSc().applyProperties(style, info.props, false); + } + } else { + String sDisplayName = style.getDisplayName(); + if (styleMap.contains(sDisplayName)) { + // Apply attributes as specified in style map from user + XhtmlStyleMapItem map = styleMap.get(sDisplayName); + info.sTagName = map.sBlockElement; + if (!"(none)".equals(map.sBlockCss)) { + info.sClass = map.sBlockCss; + } + } else if (style != ofr.getHeadingStyle(nLevel)) { + // This is not the main style for this level, add class and remember + styleNames.addName(sDisplayName); + info.sClass = styleNames.getName(sDisplayName); + if (1 <= nLevel && nLevel <= 6) { + otherLevelStyles.get(nLevel).add(sDisplayName); + } + } + } + } } /** Apply an inner style on a heading. The inner style surrounds the text content, excluding the numbering label. diff --git a/src/main/java/writer2latex/xhtml/style/ListStyleParser.java b/src/main/java/writer2latex/xhtml/style/ListStyleParser.java index 53dc03e..bf0efdd 100644 --- a/src/main/java/writer2latex/xhtml/style/ListStyleParser.java +++ b/src/main/java/writer2latex/xhtml/style/ListStyleParser.java @@ -78,8 +78,8 @@ public class ListStyleParser extends StyleParser { } } else { - info.sClass = "listlevel"+Integer.toString(nLevel) - +styleNames.addToExport(sDisplayName); + styleNames.addName(sDisplayName); + info.sClass = "listlevel"+Integer.toString(nLevel)+styleNames.getName(sDisplayName); } } } @@ -106,7 +106,8 @@ public class ListStyleParser extends StyleParser { buf.append(indent); buf.append(".listlevel"); buf.append(nLevel); - buf.append(styleNames.addToExport(sDisplayName)); + styleNames.addName(sDisplayName); + buf.append(styleNames.getName(sDisplayName)); buf.append(" {"); buf.append(props.toString()); buf.append("}"); @@ -120,7 +121,8 @@ public class ListStyleParser extends StyleParser { buf.append(indent); buf.append(".listlevel"); buf.append(nLevel); - buf.append(styleNames.addToExport(sDisplayName)); + styleNames.addName(sDisplayName); + buf.append(styleNames.getName(sDisplayName)); buf.append(" p {"); buf.append(parProps.toString()); buf.append("}"); diff --git a/src/main/java/writer2latex/xhtml/style/PageStyleParser.java b/src/main/java/writer2latex/xhtml/style/PageStyleParser.java index 1a1ab78..5253232 100644 --- a/src/main/java/writer2latex/xhtml/style/PageStyleParser.java +++ b/src/main/java/writer2latex/xhtml/style/PageStyleParser.java @@ -123,7 +123,8 @@ public class PageStyleParser extends StyleParser { String sDisplayName = masterPage.getDisplayName(); if (ofr.isPresentation()) { // Always generates class name - info.sClass="masterpage"+styleNames.addToExport(sDisplayName); + styleNames.addName(sDisplayName); + info.sClass="masterpage"+styleNames.getName(sDisplayName); } } } @@ -156,7 +157,8 @@ public class PageStyleParser extends StyleParser { // Then export the results buf.append(indent); buf.append(".masterpage"); - buf.append(styleNames.addToExport(sDisplayName)); + styleNames.addName(sDisplayName); + buf.append(styleNames.getName(sDisplayName)); buf.append(" {"); buf.append(info.props.toString()); buf.append("}"); diff --git a/src/main/java/writer2latex/xhtml/style/PresentationStyleParser.java b/src/main/java/writer2latex/xhtml/style/PresentationStyleParser.java index 16d1280..71a008d 100644 --- a/src/main/java/writer2latex/xhtml/style/PresentationStyleParser.java +++ b/src/main/java/writer2latex/xhtml/style/PresentationStyleParser.java @@ -105,7 +105,8 @@ public class PresentationStyleParser extends FrameStyleParser { if (!props.isEmpty()) { buf.append(indent); buf.append("li.outline"); - buf.append(styleNames.addToExport(sDisplayName)); + styleNames.addName(sDisplayName); + buf.append(styleNames.getName(sDisplayName)); buf.append(" p {"); buf.append(props.toString()); buf.append("}"); @@ -151,7 +152,9 @@ public class PresentationStyleParser extends FrameStyleParser { public void applyOutlineStyle(int nLevel, StyleInfo info) { if (2<=nLevel && nLevel<=9 && sCurrentOutlineStyle!=null) { if (outlineStyles.containsKey(sCurrentOutlineStyle)) { - info.sClass = "outline"+outlineStyleNames.addToExport(outlineStyles.get(sCurrentOutlineStyle)[nLevel]); + String name = outlineStyles.get(sCurrentOutlineStyle)[nLevel]; + outlineStyleNames.addName(name); + info.sClass = "outline"+outlineStyleNames.getName(name); } } } diff --git a/src/main/java/writer2latex/xhtml/style/StyleWithPropertiesParser.java b/src/main/java/writer2latex/xhtml/style/StyleWithPropertiesParser.java index b921326..1fb125e 100644 --- a/src/main/java/writer2latex/xhtml/style/StyleWithPropertiesParser.java +++ b/src/main/java/writer2latex/xhtml/style/StyleWithPropertiesParser.java @@ -84,8 +84,9 @@ public abstract class StyleWithPropertiesParser extends StyleParser { } else { // Generate class name from display name + styleNames.addName(sDisplayName); info.sClass = getClassNamePrefix() - + styleNames.addToExport(sDisplayName); + + styleNames.getName(sDisplayName); } } } @@ -110,7 +111,8 @@ public abstract class StyleWithPropertiesParser extends StyleParser { buf.append(getStyleTag()); buf.append("."); buf.append(getClassNamePrefix()); - buf.append(styleNames.addToExport(sDisplayName)); + styleNames.addName(sDisplayName); + buf.append(styleNames.getName(sDisplayName)); buf.append(" {"); buf.append(props.toString()); buf.append("}"); diff --git a/src/main/java/writer2latex/xhtml/style/TextStyleParser.java b/src/main/java/writer2latex/xhtml/style/TextStyleParser.java index 2ec2736..9497caa 100644 --- a/src/main/java/writer2latex/xhtml/style/TextStyleParser.java +++ b/src/main/java/writer2latex/xhtml/style/TextStyleParser.java @@ -136,11 +136,13 @@ public class TextStyleParser extends StyleWithPropertiesParser { // This combination is not seen before, but the base style may be known // In that case, use the visited style name as well if (anchorStyleNames.containsName(sStyleName)) { - sExportName = anchorStyleNames.addToExport(sStyleName) - +anchorVisitedStyleNames.addToExport(sVisitedStyleName); + anchorStyleNames.addName(sStyleName); + anchorStyleNames.addName(sVisitedStyleName); + sExportName = anchorStyleNames.getName(sStyleName)+anchorVisitedStyleNames.getName(sVisitedStyleName); } else { - sExportName = anchorStyleNames.addToExport(sStyleName); + anchorStyleNames.addName(sStyleName); + sExportName = anchorStyleNames.getName(sStyleName); } anchorCombinedStyleNames.put(sName,sExportName); orgAnchorStyleNames.put(sExportName,sStyleName);