mirror of
https://github.com/xiaoqidun/ofdgo.git
synced 2026-10-30 09:37:26 +08:00
This commit is contained in:
1 parent
c15547f0d2
commit
f44d0d8a60
30 files changed
+2075
-463
No files matched your search
@@ -0,0 +1,88 @@
|
||||
// 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 ofdgo
|
||||
|
||||
import "image/color"
|
||||
|
||||
// CompilePage 使用公共OFD语义和配置的字形、几何能力编译页面
|
||||
// 入参: r 渲染器, page 页面
|
||||
// 返回: *RasterPage 绘制页面, error 编译错误
|
||||
func (GGBackend) CompilePage(r *Renderer, page *PageContent) (*RasterPage, error) {
|
||||
box, err := r.GetPageBox(page)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
c, err := newSemanticCompiler(r)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
c.page = &RasterPage{Width: box.W, Height: box.H, DPI: r.DPI}
|
||||
if _, _, err := c.page.PixelSize(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if !r.TransparentBackground {
|
||||
if err := c.fill(geometryRectangle(Box{W: box.W, H: box.H}), Paint{Kind: PaintSolid, Color: color.RGBA{255, 255, 255, 255}}, false, nil, IdentityMatrix, IdentityMatrix); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
if err := r.WalkPage(page, c); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if r.OnPageText != nil {
|
||||
r.OnPageText(page, &c.text)
|
||||
}
|
||||
return c.page, nil
|
||||
}
|
||||
|
||||
// PageText 提取与GG页面绘制相同定位的原文,不读取图片像素
|
||||
// 入参: r 渲染器, page 页面
|
||||
// 返回: *PageText 页面文字, error 定位错误
|
||||
func (GGBackend) PageText(r *Renderer, page *PageContent) (*PageText, error) {
|
||||
if _, err := r.GetPageBox(page); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
c, err := newSemanticCompiler(r)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
c.textOnly = true
|
||||
if err := r.WalkPage(page, c); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &c.text, nil
|
||||
}
|
||||
|
||||
// MeasureObject 复用文字和图形编译规则收集范围,不分配页面像素
|
||||
// 入参: r 渲染器, object 对象, options 度量上下文
|
||||
// 返回: ObjectMeasurement 对象范围与轮廓, error 度量错误
|
||||
func (GGBackend) MeasureObject(r *Renderer, object GraphicObject, options MeasureOptions) (ObjectMeasurement, error) {
|
||||
c, err := newSemanticCompiler(r)
|
||||
if err != nil {
|
||||
return ObjectMeasurement{}, err
|
||||
}
|
||||
boundary, ctm := editorGeometry(object)
|
||||
if _, err := creationBox(boundary); err != nil {
|
||||
return ObjectMeasurement{}, err
|
||||
}
|
||||
if ctm != "" {
|
||||
if _, err := creationNumbers(ctm, 6); err != nil {
|
||||
return ObjectMeasurement{}, err
|
||||
}
|
||||
}
|
||||
c.measure = true
|
||||
c.contours = options.Contours
|
||||
err = r.WalkObject(&object, RenderState{Defaults: options.Defaults, Parent: options.Parent, BoundaryInCTM: options.BoundaryInCTM, Clip: options.Clip}, c)
|
||||
return c.measurement, err
|
||||
}
|
||||
Reference in new issue
Block a user