kerry
6 years ago
14 changed files with 993 additions and 674 deletions
@ -0,0 +1,80 @@
|
||||
package com.fr.third.v2.lowagie.text.html; |
||||
|
||||
import com.fr.third.ibm.icu.text.BreakIterator; |
||||
|
||||
import java.text.CharacterIterator; |
||||
|
||||
/** |
||||
* 之前性能插件里面的考虑空格和标点符号的分词iterator |
||||
*/ |
||||
public class SpaceWithPunctuationBreakIterator extends BreakIterator { |
||||
|
||||
private BreakIterator iterator; |
||||
private int currentPos = -1; |
||||
private int currentIndex = -1; |
||||
private boolean[] spaceIndex; |
||||
|
||||
public SpaceWithPunctuationBreakIterator(String text, BreakIterator iterator){ |
||||
this.iterator = iterator; |
||||
iterator.setText(text); |
||||
this.spaceIndex = new boolean[text.length()]; |
||||
int ilen = text.length() - 1; |
||||
if(ilen > 0) { |
||||
for (int i = 0; i < ilen; i++) { |
||||
char c = text.charAt(i); |
||||
spaceIndex[i + 1] = (c == ' ' && isPunctuation(text.charAt(i + 1)) )|| c == '-' || c == '\u2010' || c== '\n'; |
||||
} |
||||
} |
||||
} |
||||
|
||||
public boolean isPunctuation(char c) { |
||||
int code = Character.getType(c); |
||||
return code == 24 || code == 20 || code == 21 || code == 22 || code == 23; |
||||
} |
||||
|
||||
public int first() { |
||||
throw new UnsupportedOperationException(); |
||||
} |
||||
|
||||
public int last() { |
||||
throw new UnsupportedOperationException(); |
||||
} |
||||
|
||||
public int next(int n) { |
||||
throw new UnsupportedOperationException(); |
||||
} |
||||
|
||||
public int next() { |
||||
if(currentIndex == currentPos) { |
||||
currentPos = this.iterator.next(); |
||||
} |
||||
for(int i = currentIndex + 1; i < currentPos; i++){ |
||||
if(spaceIndex[i]){ |
||||
currentIndex = i; |
||||
return currentIndex; |
||||
} |
||||
} |
||||
currentIndex = currentPos; |
||||
return currentIndex; |
||||
} |
||||
|
||||
public int previous() { |
||||
throw new UnsupportedOperationException(); |
||||
} |
||||
|
||||
public int following(int offset) { |
||||
throw new UnsupportedOperationException(); |
||||
} |
||||
|
||||
public int current() { |
||||
throw new UnsupportedOperationException(); |
||||
} |
||||
|
||||
public CharacterIterator getText() { |
||||
throw new UnsupportedOperationException(); |
||||
} |
||||
|
||||
public void setText(CharacterIterator newText) { |
||||
throw new UnsupportedOperationException(); |
||||
} |
||||
} |
@ -0,0 +1,58 @@
|
||||
package com.fr.third.v2.lowagie.text.pdf; |
||||
|
||||
import com.fr.third.v2.lowagie.text.DocumentException; |
||||
import com.fr.third.v2.lowagie.text.html.CSSUtils; |
||||
import com.fr.third.v2.lowagie.text.html.Markup; |
||||
|
||||
import java.awt.Color; |
||||
|
||||
public class BorderStyle { |
||||
private float borderWidth = 0.0f; |
||||
private Color borderColor = Color.black; |
||||
private String borderPattern = "solid"; |
||||
|
||||
public float getBorderWidth() { |
||||
return borderWidth; |
||||
} |
||||
|
||||
public void setBorderWidth(float borderWidth) { |
||||
this.borderWidth = borderWidth; |
||||
} |
||||
|
||||
public Color getBorderColor() { |
||||
return borderColor; |
||||
} |
||||
|
||||
public void setBorderColor(Color borderColor) { |
||||
this.borderColor = borderColor; |
||||
} |
||||
|
||||
public String getBorderPattern() { |
||||
return borderPattern; |
||||
} |
||||
|
||||
public void setBorderPattern(String borderPattern) { |
||||
this.borderPattern = borderPattern; |
||||
} |
||||
|
||||
public BorderStyle() { |
||||
|
||||
} |
||||
|
||||
public BorderStyle(int borderWidth, String borderPattern, Color borderColor) { |
||||
this.borderWidth = borderWidth; |
||||
this.borderPattern = borderPattern; |
||||
this.borderWidth = borderWidth; |
||||
} |
||||
|
||||
public static BorderStyle parseBorderStyle(String borderString) throws DocumentException { |
||||
BorderStyle borderStyle = new BorderStyle(); |
||||
String[] borderPros = borderString.split(" "); |
||||
borderStyle.setBorderWidth(CSSUtils.parseFloat(borderPros[0])); |
||||
borderStyle.setBorderPattern(borderPros[1]); |
||||
borderStyle.setBorderColor(Markup.decodeColor(borderPros[2])); |
||||
return borderStyle; |
||||
|
||||
} |
||||
|
||||
} |
@ -1,12 +0,0 @@
|
||||
package com.fr.third.v2.lowagie.text.pdf; |
||||
|
||||
/** |
||||
* @author kerry |
||||
* @date 2018/8/10 |
||||
*/ |
||||
public interface PdfBlock { |
||||
float getHeight(); |
||||
void calculateHeight(); |
||||
|
||||
String toHtmlString(double startY, double endY); |
||||
} |
@ -0,0 +1,52 @@
|
||||
package com.fr.third.v2.lowagie.text.pdf; |
||||
|
||||
/** |
||||
* 描述table的属性类 |
||||
* 包括cellspacing、cellpadding、border等 |
||||
*/ |
||||
public class TableProperties { |
||||
private BorderStyle borderStyle = new BorderStyle(); |
||||
private float cellspacing = 2.0f; |
||||
private float cellpadding = 1.0f; |
||||
private boolean collapse = false; |
||||
|
||||
public BorderStyle getBorderStyle() { |
||||
return borderStyle; |
||||
} |
||||
|
||||
public void setBorderStyle(BorderStyle borderStyle) { |
||||
this.borderStyle = borderStyle; |
||||
} |
||||
|
||||
public float getCellspacing() { |
||||
return cellspacing; |
||||
} |
||||
|
||||
public void setCellspacing(float cellspacing) { |
||||
this.cellspacing = cellspacing; |
||||
} |
||||
|
||||
public float getCellpadding() { |
||||
return cellpadding; |
||||
} |
||||
|
||||
public void setCellpadding(float cellpadding) { |
||||
this.cellpadding = cellpadding; |
||||
} |
||||
|
||||
public boolean isCollapse() { |
||||
return collapse; |
||||
} |
||||
|
||||
public void setCollapse(boolean collapse) { |
||||
this.collapse = collapse; |
||||
} |
||||
|
||||
public String toHtmlString(){ |
||||
StringBuffer sb = new StringBuffer(); |
||||
sb.append("cellspacing").append("=").append(cellspacing).append(" "); |
||||
sb.append("cellpadding").append("=").append(cellpadding).append(" "); |
||||
sb.append("border").append("=").append(borderStyle.getBorderWidth()).append(" "); |
||||
return sb.toString(); |
||||
} |
||||
} |
Loading…
Reference in new issue