本文整理汇总了Java中org.apache.pdfbox.text.TextPosition.getX方法的典型用法代码示例。如果您正苦于以下问题:Java TextPosition.getX方法的具体用法?Java TextPosition.getX怎么用?Java TextPosition.getX使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.pdfbox.text.TextPosition
的用法示例。
在下文中一共展示了TextPosition.getX方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: TextMetrics
import org.apache.pdfbox.text.TextPosition; //导入方法依赖的package包/类
public TextMetrics(TextPosition tp)
{
x = tp.getX();
baseline = tp.getY();
font = tp.getFont();
width = tp.getWidth();
height = tp.getHeight();
pointSize = tp.getFontSizeInPt();
fontSize = tp.getYScale();
ascent = getAscent();
descent = getDescent();
}
示例2: append
import org.apache.pdfbox.text.TextPosition; //导入方法依赖的package包/类
public void append(TextPosition tp)
{
width += tp.getX() - (x + width) + tp.getWidth();
height = Math.max(height, tp.getHeight());
ascent = Math.max(ascent, getAscent(tp.getFont(), tp.getYScale()));
descent = Math.min(descent, getDescent(tp.getFont(), tp.getYScale()));
}
示例3: toPDFToken
import org.apache.pdfbox.text.TextPosition; //导入方法依赖的package包/类
public PDFToken toPDFToken() {
val builder = PDFToken.builder();
String tokenText = textPositions.stream().map(TextPosition::getUnicode).collect(Collectors.joining(""));
// HACK(aria42) assumes left-to-right text
TextPosition firstTP = textPositions.get(0);
PDFont pdFont = firstTP.getFont();
val desc = pdFont.getFontDescriptor();
String fontFamily = desc == null ? PDFFontMetrics.UNKNWON_FONT_FAMILY : desc.getFontName();
float ptSize = firstTP.getFontSizeInPt();
//HACK(ddowney): it appears that sometimes (maybe when half-pt font sizes are used), pdfbox 2.0 will multiply
// all of the true font sizes by 10. If we detect this is likely, we divide font size by ten:
if(ptSize > 45.0f)
ptSize /= 10.0f;
//HACK(ddowney): ensure unique sizes get unique names/objects:
fontFamily += "_" + ptSize + "_" + firstTP.getWidthOfSpace();
val fontMetrics = PDFFontMetrics.of(fontFamily, ptSize, firstTP.getWidthOfSpace());
builder.fontMetrics(fontMetrics);
float minX = Float.POSITIVE_INFINITY;
float maxX = Float.NEGATIVE_INFINITY;
float minY = Float.POSITIVE_INFINITY;
float maxY = Float.NEGATIVE_INFINITY;
for (TextPosition tp : textPositions) {
float x0 = tp.getX();
if (x0 < minX) {
minX = x0;
}
float x1 = x0 + tp.getWidth();
if (x1 > maxX) {
maxX = x1;
}
float y0 = tp.getY() - tp.getHeight(); //getY returns the bottom-left
if (y0 < minY) {
minY = y0;
}
float y1 = tp.getY();
if (y1 > maxY) {
maxY = y1;
}
}
FloatList bounds = FloatArrayList.newListWith(minX, minY, maxX, maxY);
builder.bounds(bounds);
tokenText = discardSuperscripts(tokenText, bounds);
// separate ligands
tokenText = Normalizer.normalize(tokenText, Normalizer.Form.NFKC);
builder.token(tokenText);
return builder.build();
}
示例4: processTextPosition
import org.apache.pdfbox.text.TextPosition; //导入方法依赖的package包/类
@Override
protected void processTextPosition(TextPosition text)
{
if (text.isDiacritic())
{
lastDia = text;
}
else if (!text.getUnicode().trim().isEmpty())
{
if (lastDia != null)
{
if (text.contains(lastDia))
text.mergeDiacritic(lastDia);
lastDia = null;
}
/*float[] c = transformPosition(text.getX(), text.getY());
cur_x = c[0];
cur_y = c[1];*/
cur_x = text.getX();
cur_y = text.getY();
/*System.out.println("Text: " + text.getCharacter());
System.out.println(" Font size: " + text.getFontSize() + " " + text.getFontSizeInPt() + "pt");
System.out.println(" Width: " + text.getWidth());
System.out.println(" Width adj: " + text.getWidthDirAdj());
System.out.println(" Height: " + text.getHeight());
System.out.println(" Height dir: " + text.getHeightDir());
System.out.println(" XScale: " + text.getXScale());
System.out.println(" YScale: " + text.getYScale());*/
float distx = 0;
float disty = 0;
if (lastText != null)
{
distx = text.getX() - (lastText.getX() + lastText.getWidth());
disty = text.getY() - lastText.getY();
}
//should we split the boxes?
boolean split = lastText == null || distx > 1.0f || distx < -6.0f || Math.abs(disty) > 1.0f
|| isReversed(getTextDirectionality(text)) != isReversed(getTextDirectionality(lastText));
//if the style changed, we should split the boxes
updateStyle(style, text);
if (!style.equals(curstyle))
split = true;
if (split) //start of a new box
{
//finish current box (if any)
if (lastText != null)
{
finishBox();
}
//start a new box
curstyle = new BoxStyle(style);
}
textLine.append(text.getUnicode());
if (textMetrics == null)
textMetrics = new TextMetrics(text);
else
textMetrics.append(text);
lastText = text;
}
}