mirror of
https://github.com/xiaoqidun/ofdgo.git
synced 2026-10-29 17:27:08 +08:00
1 parent
bec13d523f
commit
b3c4bbc844
45 files changed
+1885
-1453
No files matched your search
@@ -0,0 +1,40 @@
|
||||
// Copyright 2025-2026 肖其顿 (XIAO QI DUN)
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package pdf
|
||||
|
||||
import (
|
||||
"github.com/xiaoqidun/pdfgo"
|
||||
)
|
||||
|
||||
// PageMatrix 将裁剪框、用户单位及页面旋转转换为OFD毫米坐标
|
||||
// 入参: page PDF页面
|
||||
// 返回: pdfgo.Matrix 坐标变换, float64 页面宽度, float64 页面高度
|
||||
func PageMatrix(page *pdfgo.Page) (pdfgo.Matrix, float64, float64) {
|
||||
b := page.CropBox
|
||||
scale := 25.4 / 72 * page.UserUnit
|
||||
width, height := (b.XMax-b.XMin)*scale, (b.YMax-b.YMin)*scale
|
||||
m := pdfgo.Matrix{scale, 0, 0, -scale, -b.XMin * scale, b.YMax * scale}
|
||||
switch page.Rotation {
|
||||
case 90:
|
||||
m = pdfgo.Matrix{0, 1, -1, 0, height, 0}.Mul(m)
|
||||
width, height = height, width
|
||||
case 180:
|
||||
m = pdfgo.Matrix{-1, 0, 0, -1, width, height}.Mul(m)
|
||||
case 270:
|
||||
m = pdfgo.Matrix{0, -1, 1, 0, 0, width}.Mul(m)
|
||||
width, height = height, width
|
||||
}
|
||||
return m, width, height
|
||||
}
|
||||
Reference in new issue
Block a user