2016-09-20 606 views
2

我無法理解PDPageContentStream.setTextMatrix(Matrix m)參數表示的m矩陣中的6個值。早些時候它曾經有6個值,但現在它只需要一個包含所有值的矩陣。瞭解PDPageContentStream.setTextMatrix()的參數

是的,我已經閱讀文檔,我發現的解釋完全沒用 -

public void setTextMatrix(double a, 
      double b, 
      double c, 
      double d, 
      double e, 
      double f) 
       throws IOException 

The Tm operator. Sets the text matrix to the given values. A current text matrix will be replaced with the new one. 

Parameters: 
a - The a value of the matrix. 
b - The b value of the matrix. 
c - The c value of the matrix. 
d - The d value of the matrix. 
e - The e value of the matrix. 
f - The f value of the matrix. 

我也搜索的例​​子,但無處沒有我發現這些值的解釋。此外,奇怪的是,當我用兩個不同的PDF文件嘗試相同的值時,結果是不同的,所以我假設這與邊距和距離等有關。

我覺得我在浪費時間猜測工作。對論點的直接解釋將會非常好。

編輯

我知道的矩陣,以及如何傳遞值。我不知道矩陣中的值實際上是什麼意思。

+0

查看編輯。 – user8

+0

也許在java文檔中閱讀AffineTransform的解釋,除了參數不同之外,它們是相同的。另請參閱Matrix的靜態方法。* –

+0

另請閱讀處理座標系的pdf規範部分。 – mkl

回答

2

你可以嘗試繞開新方法的要求,使用的Matrix constructors

setTextMatrix(new Matrix(Double.valueOf(a).floatValue(), 
          Double.valueOf(b).floatValue(), 
          Double.valueOf(c).floatValue(), 
          Double.valueOf(d).floatValue(), 
          Double.valueOf(e).floatValue(), 
          Double.valueOf(f).floatValue())) 

一個與失去一些double準確性的風險小。

編輯:
你可以看看這個例子 - UsingTextMatrix

每PDPageContentStream.java這是過時的setTextMethod,爲您詢問:

@Deprecated 
public void setTextMatrix(double a, double b, double c, double d, double e, double f) throws IOException 
{ 
    setTextMatrix(new Matrix((float)a, (float)b, (float)c, (float)d, (float)e, (float)f)); 
} 

,基本上做什麼,我試過以上。因此,除了更緊湊的用法外,不應有任何重大差異。欲瞭解更多信息org.apache.pdfbox.pdmodel.PDPageContentStream類。

關於單浮點/雙精度值的含義:

a, b, c, d, e, f定義表單的一個org.apache.pdfbox.cos.COSArray

static final float[] DEFAULT_SINGLE = 
{ 
     a,b,0, 
     c,d,0, 
     e,f,1 
}; 

其中

a stands for ScaleX 
b stands for ShearY 
c stands for ShearX 
d stands for ScaleY 
e stands for TranslateX 
f stands for TranslateY 

在這裏,在這個Wiki about Affine Transformations你能讀懂你可以用這些值做什麼。並在下文中在視覺上表示的可能的操作: enter image description here

注意:有一個在tXtYorg.apache.pdfbox.util.Matrix位置和上方的圖像的微小差異。

希望能夠解決這個問題。

+1

查看我編輯的問題。 –

+0

你只是告訴我關於數據類型,你不告訴我什麼是數值,什麼是數值等等。這些是x/y座標還是翻譯等 –

+0

@Yuganka你知道嗎?線性代數?特別是如何將翻譯,旋轉等數學表示爲仿射變換,以及如何通過在三維空間中嵌入二維平面,您可以藉助於3×3矩陣的子集對平面的仿射變換進行建模?在計算機圖形學中,你通常需要知道一些基本的數學知識。 – mkl