Browse Source

引入依赖microsoft-yahei-ui

sunyj 8 years ago
parent
commit
b1db08c040
2 changed files with 27 additions and 5 deletions
  1. 5 0
      pom.xml
  2. 22 5
      src/main/java/com/uas/report/service/impl/PrintServiceImpl.java

+ 5 - 0
pom.xml

@@ -118,6 +118,11 @@
 			<artifactId>msyahei</artifactId>
 			<version>1.0.0</version>
 		</dependency>
+		<dependency>
+			<groupId>com.uas.report</groupId>
+			<artifactId>microsoft-yahei-ui</artifactId>
+			<version>1.0.0</version>
+		</dependency>
 
 		<!-- 文件上传 -->
 		<dependency>

+ 22 - 5
src/main/java/com/uas/report/service/impl/PrintServiceImpl.java

@@ -444,6 +444,9 @@ public class PrintServiceImpl implements PrintService {
 		for (Element textElement : textElements) {
 			// 获取font节点
 			Element fontElement = (Element) textElement.selectSingleNode("*[name()='font']");
+			if (fontElement == null) {
+				continue;
+			}
 			// 将字体MSYahei改为Microsoft YaHei UI
 			Attribute fontName = fontElement.attribute("fontName");
 			if (Objects.equals(fontName.getText(), "MSYahei")) {
@@ -456,11 +459,25 @@ public class PrintServiceImpl implements PrintService {
 				// 如果textElement节点指定isStretchWithOverflow为true(可换行),则调整行距
 				Attribute isStretchWithOverflow = parent.attribute("isStretchWithOverflow");
 				if (isStretchWithOverflow != null && Objects.equals(isStretchWithOverflow.getText(), "true")) {
-					// 添加节点paragraph,调整行距为固定值12磅
-					Element paragraphElement = new DefaultElement("paragraph", textElement.getNamespace());
-					paragraphElement.addAttribute("lineSpacing", "Fixed");
-					paragraphElement.addAttribute("lineSpacingSize", "12.0");
-					textElement.add(paragraphElement);
+					// 修改paragraph节点
+					Element paragraphElement = (Element) textElement.selectSingleNode("*[name()='paragraph']");
+					if (paragraphElement == null) {
+						paragraphElement = new DefaultElement("paragraph", textElement.getNamespace());
+						textElement.add(paragraphElement);
+					}
+					// 调整行距为固定值12磅
+					Attribute lineSpacing = paragraphElement.attribute("lineSpacing");
+					if (lineSpacing != null) {
+						lineSpacing.setText("Fixed");
+					} else {
+						paragraphElement.addAttribute("lineSpacing", "Fixed");
+					}
+					Attribute lineSpacingSize = paragraphElement.attribute("lineSpacingSize");
+					if (lineSpacingSize != null) {
+						lineSpacingSize.setText("12.0");
+					} else {
+						paragraphElement.addAttribute("lineSpacingSize", "12.0");
+					}
 				}
 			}
 		}