Browse Source

Pull request #467: REPORT-33491 REPORT-33029 无插件PDF导出-HTML解析:支持<th>标签加粗样式 ; 块元素(如:div、p)支持align、text-align属性

Merge in CORE/base-third from ~HUGH.C/base-third:release/10.0 to release/10.0

* commit 'd213b85dd5558559fdba23d55b3c56dcac54cf32':
  REPORT-33029 无插件PDF导出-HTML解析:块元素(如:div、p)支持align、text-align属性
  REPORT-33491 无插件PDF导出-HTML解析:支持<th>标签加粗样式
release/10.0
Hugh.C 5 years ago
parent
commit
6f3959afd8
  1. 1
      fine-itext-old/src/main/java/com/fr/third/com/lowagie/text/pdf/PdfGraphics2D.java
  2. 3
      fine-itext/src/main/java/com/fr/third/v2/lowagie/text/html/Markup.java
  3. 36
      fine-itext/src/main/java/com/fr/third/v2/lowagie/text/html/simpleparser/FactoryProperties.java
  4. 3
      fine-itext/src/main/java/com/fr/third/v2/lowagie/text/html/simpleparser/HTMLWorker.java
  5. 4
      fine-itext/src/main/java/com/fr/third/v2/lowagie/text/html/simpleparser/IncCell.java

1
fine-itext-old/src/main/java/com/fr/third/com/lowagie/text/pdf/PdfGraphics2D.java

@ -433,6 +433,7 @@ public class PdfGraphics2D extends Graphics2D {
cb.setTextRenderingMode(PdfContentByte.TEXT_RENDER_MODE_FILL_STROKE);
if (strokeWidth != 1) {
cb.setLineWidth(strokeWidth);
oldStroke = new BasicStroke(strokeWidth);
if(realPaint instanceof Color){
Color color = (Color)realPaint;
int alpha = color.getAlpha();

3
fine-itext/src/main/java/com/fr/third/v2/lowagie/text/html/Markup.java

@ -203,6 +203,9 @@ public class Markup {
/** the CSS tag for the horizontal alignment of an object */
public static final String CSS_KEY_TEXTALIGN = "text-align";
/** the CSS tag for the horizontal alignment of an object */
public static final String CSS_KEY_ALIGN = "align";
/** the CSS tag for text decorations */
public static final String CSS_KEY_TEXTDECORATION = "text-decoration";

36
fine-itext/src/main/java/com/fr/third/v2/lowagie/text/html/simpleparser/FactoryProperties.java

@ -154,15 +154,6 @@ public class FactoryProperties {
}
public static void createParagraph(Paragraph p, ChainedProperties props) {
String value = props.getProperty("align");
if (value != null) {
if (value.equalsIgnoreCase("center"))
p.setAlignment(Element.ALIGN_CENTER);
else if (value.equalsIgnoreCase("right"))
p.setAlignment(Element.ALIGN_RIGHT);
else if (value.equalsIgnoreCase("justify"))
p.setAlignment(Element.ALIGN_JUSTIFIED);
}
if(props.hasPropertyInChain("div", "background")){
p.setBackground(props.getPropertyFromChain("div", "background"));
}
@ -173,6 +164,7 @@ public class FactoryProperties {
p.setAttribute("noexist-attrid", props.getProperty("noexist-attrid"));
}
parseAlignAttr(p, props);
parseMarginAttr(p, props);
parsePaddingAttr(p, props);
@ -187,7 +179,7 @@ public class FactoryProperties {
p.setHyphenation(getHyphenation(props));
setParagraphLeading(p, props.getProperty("leading"));
value = props.getProperty("before");
String value = props.getProperty("before");
if (value != null) {
try {
p.setSpacingBefore(Float.parseFloat(value));
@ -210,6 +202,30 @@ public class FactoryProperties {
}
}
/**
* 解析align属性
*
* @param p
* @param props
*/
private static void parseAlignAttr(Paragraph p, ChainedProperties props) {
String[] keys = new String[]{Markup.CSS_KEY_ALIGN, Markup.CSS_KEY_TEXTALIGN};
for (String key : keys) {
String value = props.getPropertyFromChain("div", key);
if (null == value) {
continue;
}
if (value.equalsIgnoreCase("center"))
p.setAlignment(Element.ALIGN_CENTER);
else if (value.equalsIgnoreCase("right"))
p.setAlignment(Element.ALIGN_RIGHT);
else if (value.equalsIgnoreCase("left"))
p.setAlignment(Element.ALIGN_LEFT);
else if (value.equalsIgnoreCase("justify"))
p.setAlignment(Element.ALIGN_JUSTIFIED);
}
}
/**
* 解析margin属性
*

3
fine-itext/src/main/java/com/fr/third/v2/lowagie/text/html/simpleparser/HTMLWorker.java

@ -491,6 +491,9 @@ public class HTMLWorker implements SimpleXMLDocHandler, DocListener {
endElement(tag);
skipText = false;
pendingTD = true;
if (tag.equals("th")) {
h.put("b", null);
}
cprops.addToChain("td", h);
stack.push(new IncCell(tag, cprops));
return;

4
fine-itext/src/main/java/com/fr/third/v2/lowagie/text/html/simpleparser/IncCell.java

@ -74,8 +74,8 @@ public class IncCell implements TextElementArray {
if (value != null)
cell.setColspan(Integer.parseInt(value));
value = props.getProperty("align");
if (tag.equals("th"))
cell.setHorizontalAlignment(Element.ALIGN_CENTER);
// if (tag.equals("th"))
// cell.setHorizontalAlignment(Element.ALIGN_CENTER);
if (value != null) {
if ("center".equalsIgnoreCase(value))
cell.setHorizontalAlignment(Element.ALIGN_CENTER);

Loading…
Cancel
Save