Skip to content

Commit 5d0d6de

Browse files
committed
Merge branch 'main' of github.com:klippa-app/go-pdfium
2 parents 7203aa5 + 4d84e74 commit 5d0d6de

File tree

38 files changed

+2085
-14
lines changed

38 files changed

+2085
-14
lines changed

internal/implementation_cgo/text_experimental.go

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import "C"
1010

1111
import (
1212
"bytes"
13+
"math"
1314
"unsafe"
1415

1516
"github.com/klippa-app/go-pdfium/responses"
@@ -35,10 +36,19 @@ func (p *PdfiumImplementation) getFontInformation(textPage C.FPDF_TEXTPAGE, char
3536
fontName = string(bytes.TrimSuffix(rawFontName, []byte("\x00")))
3637
}
3738

39+
renderedSize := float64(fontSize)
40+
41+
matrix := C.FS_MATRIX{}
42+
success := C.FPDFText_GetMatrix(textPage, C.int(charIndex), &matrix)
43+
if int(success) != 0 {
44+
renderedSize = float64(fontSize) * math.Sqrt(float64(matrix.c)*float64(matrix.c)+float64(matrix.d)*float64(matrix.d))
45+
}
46+
3847
return &responses.FontInformation{
39-
Size: float64(fontSize),
40-
Weight: int(fontWeight),
41-
Name: fontName,
42-
Flags: int(fontFlags),
48+
Size: float64(fontSize),
49+
RenderedSize: renderedSize,
50+
Weight: int(fontWeight),
51+
Name: fontName,
52+
Flags: int(fontFlags),
4353
}
4454
}

internal/implementation_cgo/text_no_experimental.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ func (p *PdfiumImplementation) getFontInformation(textPage C.FPDF_TEXTPAGE, char
1616
fontSize := C.FPDFText_GetFontSize(textPage, C.int(charIndex))
1717

1818
return &responses.FontInformation{
19-
Size: float64(fontSize),
19+
Size: float64(fontSize),
20+
RenderedSize: float64(fontSize),
2021
}
2122
}

internal/implementation_webassembly/text.go

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -436,10 +436,29 @@ func (p *PdfiumImplementation) getFontInformation(textPage uint64, charIndex int
436436
return nil, err
437437
}
438438

439+
renderedSize := fontSize
440+
441+
matrixPointer, matrixValue, err := p.CStructFS_MATRIX(nil)
442+
if err == nil {
443+
defer p.Free(matrixPointer)
444+
445+
res, err = p.Module.ExportedFunction("FPDFText_GetMatrix").Call(p.Context, textPage, *(*uint64)(unsafe.Pointer(&charIndex)), matrixPointer)
446+
if err == nil {
447+
success := *(*int32)(unsafe.Pointer(&res[0]))
448+
if int(success) != 0 {
449+
matrix, err := matrixValue()
450+
if err == nil {
451+
renderedSize = fontSize * math.Sqrt(float64(matrix.C)*float64(matrix.C)+float64(matrix.D)*float64(matrix.D))
452+
}
453+
}
454+
}
455+
}
456+
439457
return &responses.FontInformation{
440-
Size: float64(fontSize),
441-
Weight: int(fontWeight),
442-
Name: fontName,
443-
Flags: int(fontFlags),
458+
Size: float64(fontSize),
459+
RenderedSize: renderedSize,
460+
Weight: int(fontWeight),
461+
Name: fontName,
462+
Flags: int(fontFlags),
444463
}, nil
445464
}

responses/text.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,12 @@ type CharPosition struct {
1313
}
1414

1515
type FontInformation struct {
16-
Size float64 // Font size in points (also known as em).
17-
SizeInPixels *int // Font size in pixels, only available when PixelPositions is used.
18-
Weight int // The weight of the font, can be negative for spaces and newlines. Will only be filled when compiled with experimental support.
19-
Name string // The name of the font, can be empty for spaces and newlines. Will only be filled when compiled with experimental support.
20-
Flags int // Font flags, should be interpreted per PDF spec 1.7, Section 5.7.1 Font Descriptor Flags. Will only be filled when compiled with experimental support.
16+
Size float64 // Font size in points (also known as em).
17+
RenderedSize float64 // The effective rendered size: fontSize * sqrt(C² + D²) where C,D come from the text transformation matrix (FPDFText_GetMatrix). Falls back to Size when experimental support is not available.
18+
SizeInPixels *int // Font size in pixels, only available when PixelPositions is used.
19+
Weight int // The weight of the font, can be negative for spaces and newlines. Will only be filled when compiled with experimental support.
20+
Name string // The name of the font, can be empty for spaces and newlines. Will only be filled when compiled with experimental support.
21+
Flags int // Font flags, should be interpreted per PDF spec 1.7, Section 5.7.1 Font Descriptor Flags. Will only be filled when compiled with experimental support.
2122
}
2223

2324
type GetPageTextStructuredChar struct {

0 commit comments

Comments
 (0)