Skip to content

Commit

Permalink
Output text matrix for diagnosis. This should not be merged to main.
Browse files Browse the repository at this point in the history
  • Loading branch information
stephen committed Nov 1, 2023
1 parent e7d4549 commit f6f5748
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import io.mfj.textricator.text.Text
import java.io.InputStream

import com.itextpdf.kernel.colors.*
import com.itextpdf.kernel.geom.Matrix
import com.itextpdf.kernel.geom.Vector
import com.itextpdf.kernel.pdf.*
import com.itextpdf.kernel.pdf.canvas.parser.EventType
Expand Down Expand Up @@ -123,16 +124,20 @@ class Itext7TextExtractor(input:InputStream):TextExtractor {
val effMatrix = ri.textMatrix.multiply( ri.graphicsState.ctm )
val fontSize = Vector(0f,ri.fontSize,0f).cross(effMatrix)[1]

val debug = "tm:${matrix.str()} ctm:${matrix.str()}"

val text = Text(content = content, backgroundColor = null, pageNumber = pageNumber,
fontSize = fontSize, font = font, color = color,
ulx = ulx, uly = uly, lrx = lrx, lry = lry,
link = link )
link = link, debug = debug )

texts.add( text )
}
super.eventOccurred(data, type)
}

private fun Matrix.str():String = "[[${this[0]},${this[1]},${this[2]}],[${this[3]},${this[4]},${this[5]}],[${this[6]},${this[7]},${this[8]}]]"

private fun Color.getHexColor(): String? =
when ( this ) {
is DeviceRgb -> getRgb( this )
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/io/mfj/textricator/text/Text.kt
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@ data class Text(
val fontSize:Float,
val color:String? = null,
val backgroundColor:String? = null,
val link:String? = null ) {
val link:String? = null,
val debug:String? = null
) {

val width:Float
@Transient
Expand Down
6 changes: 4 additions & 2 deletions src/main/java/io/mfj/textricator/text/output/CsvTextOutput.kt
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ class CsvTextOutput(output:OutputStream):TextOutput {
"fontSize",
"fontColor",
"bgcolor",
"link"
"link",
"debug",
)
}

Expand All @@ -82,7 +83,8 @@ class CsvTextOutput(output:OutputStream):TextOutput {
text.fontSize,
text.color,
text.backgroundColor,
text.link
text.link,
text.debug
)
}

Expand Down

0 comments on commit f6f5748

Please sign in to comment.