wp: typesetting information is now an object

This commit is contained in:
minjaesong
2021-06-17 10:30:52 +09:00
parent 3bed36f2e3
commit bb6cab86f3
2 changed files with 32 additions and 16 deletions

View File

@@ -1,13 +1,11 @@
Manifest-Version: 1.0
Main-Class: net.torvald.tsvm.AppLoader
Class-Path: ./lib/GetCpuName.jar ./lib/TerranVirtualDisk.jar ./lib/annot
ations-13.0.jar ./lib/commons-codec-1.10.jar ./lib/commons-csv-1.2.jar
./lib/gdx-backend-lwjgl-natives.jar ./lib/gdx-backend-lwjgl.jar ./lib/g
dx-natives.jar ./lib/gdx.jar ./lib/graal-sdk-20.3.0.jar ./lib/icu4j-67.
1.jar ./lib/jnlp.jar ./lib/js-20.3.0.jar ./lib/js-scriptengine-20.3.0.j
ar ./lib/kotlin-reflect.jar ./lib/kotlin-stlib-1.4.0.jar ./lib/kotlin-s
tdlib-common-1.4.0.jar ./lib/kotlin-stdlib-jdk7.jar ./lib/kotlin-stdlib
-jdk8.jar ./lib/kotlin-stdlib.jar ./lib/kotlin-test.jar ./lib/kotlinx-c
oroutines-core-1.4.1.jar ./lib/regex-20.3.0.jar ./lib/truffle-api-20.3.
0.jar
Class-Path: GetCpuName.jar TerranVirtualDisk.jar annotations-13.0.jar co
mmons-codec-1.10.jar commons-csv-1.2.jar gdx-backend-lwjgl-natives.jar
gdx-backend-lwjgl.jar gdx-natives.jar gdx.jar graal-sdk-20.3.0.jar icu4
j-67.1.jar jnlp.jar js-20.3.0.jar js-scriptengine-20.3.0.jar kotlin-ref
lect.jar kotlin-stlib-1.4.0.jar kotlin-stdlib-common-1.4.0.jar kotlin-s
tdlib-jdk7.jar kotlin-stdlib-jdk8.jar kotlin-stdlib.jar kotlin-test.jar
kotlinx-coroutines-core-1.4.1.jar regex-20.3.0.jar truffle-api-20.3.0.
jar

View File

@@ -15,6 +15,13 @@ const NO_LINELAST_PUNCT = [34,39,40,60,91,123]
const TYPESET_DEBUG_PRINT = true
// bits:
// 0: set to justify; unset to ragged
// 1: set to hyphenate
const TYPESET_STRATEGY_RAGGEDRIGHT = 1024 + 0b00000000 // not implemented yet!
const TYPESET_STRATEGY_LESSRAGGED = 1024 + 0b00000010
const TYPESET_STRATEGY_JUSTIFIED = 1024 + 0b00000011 // not implemented yet!
let PAGE_HEIGHT = 60
let PAGE_WIDTH = 80
// 80x60 -> 720x1080 text area; with 72px margin for each side, paper resolution is 864x1224, which is quite close to 1:sqrt(2) ratio
@@ -26,7 +33,7 @@ let paragraphs = [
'Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. Richard McClintock, a Latin professor at Hampden-Sydney College in Virginia, looked up one of the more obscure Latin words, consectetur, from a Lorem Ipsum passage, and going through the cites of the word in classical literature, discovered the undoubtable source. Lorem Ipsum comes from sections 1.10.32 and 1.10.33 of "de Finibus Bonorum et Malorum" (The Extremes of Good and Evil) by Cicero, written in 45 BC. This book is a treatise on the theory of ethics, very popular during the Renaissance. The first line of Lorem Ipsum, "Lorem ipsum dolor sit amet..", comes from a line in section 1.10.32.',
'The standard chunk of Lorem Ipsum used since the 1500s is reproduced below for those interested. Sections 1.10.32 and 1.10.33 from "de Finibus Bonorum et Malorum" by Cicero are also reproduced in their exact original form, accompanied by English versions from the 1914 translation by H. Rackham.'
]
let typesetIndices = []
let typeset = {lineIndices: [], lineValidated: [], strategy: TYPESET_STRATEGY_LESSRAGGED}
let cursorRow = 0
let cursorCol = 0
let page = 0
@@ -102,14 +109,15 @@ function typesetAndPrint(from, toExclusive) {
let lineEnd = toExclusive || scroll + paintHeight
let printbuf = []
typesetIndices = [lineStart]
let lineIndices = []
let lineValidated = []
for (let i = 0; i < paintHeight; i++) { printbuf.push('') }
let vr = 0; let vc = 0 // virtual row/column
let text = paragraphs.slice(lineStart, lineEnd).join('\n')
function ln(i) {
vr += 1;vc = 0
typesetIndices.push(i)
lineIndices.push(i)
}
for (let i = 0; i < text.length; i++) {
@@ -130,7 +138,7 @@ function typesetAndPrint(from, toExclusive) {
printbuf[vr] += String.fromCharCode(c, c1)
ln(i)
i += (32 == c2) ? 2 : 1
typesetIndices[typesetIndices.length - 1] = i+1
lineIndices[lineIndices.length - 1] = i+1
}
else if (vc == paintWidth - 1 && NO_LINELAST_PUNCT.includes(c)) {
ln(i)
@@ -143,7 +151,7 @@ function typesetAndPrint(from, toExclusive) {
ln(i+1)
if (32 == c1 || 10 == c1) {
i += 1
typesetIndices[typesetIndices.length - 1] += 1
lineIndices[lineIndices.length - 1] += 1
}
}
// if the head-char of the word happens to sit on the rightmost side and the char right before is ' '
@@ -182,10 +190,20 @@ function typesetAndPrint(from, toExclusive) {
if (TYPESET_DEBUG_PRINT) {
for (let y = 0; y < paintHeight; y++) {
con.move(3+y, 1)
print(typesetIndices[y]+1 || '-')
print(lineIndices[y]+1 || '-')
}
}
// update typeset info
typeset.lineIndices = []
.concat(typeset.lineIndices.slice(0, lineStart))
.concat(lineIndices)
.concat(typeset.lineIndices.slice(lineEnd))
typeset.lineValidated = []
.concat(typeset.lineValidated.slice(0, lineStart))
.concat(lineIndices.map(it => true))
.concat(typeset.lineValidated.slice(lineEnd))
gotoText()
}