Fix on fonts, fixed special char printing (>=0x80) on Term, essentially changing encoding from UTF-8 to ISO-8859-1

Former-commit-id: 78d4423e896301aebdec2f27893bb2aefaf4aada
Former-commit-id: e317df0eca8da1598159648bc44c30b86663d8a5
This commit is contained in:
Song Minjae
2016-09-19 00:31:36 +09:00
parent 90ecda108d
commit 0dabe3971c
40 changed files with 64 additions and 34 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.1 KiB

After

Width:  |  Height:  |  Size: 2.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.8 KiB

After

Width:  |  Height:  |  Size: 2.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.0 KiB

After

Width:  |  Height:  |  Size: 2.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.8 KiB

After

Width:  |  Height:  |  Size: 2.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.8 KiB

After

Width:  |  Height:  |  Size: 2.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.1 KiB

After

Width:  |  Height:  |  Size: 2.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.8 KiB

After

Width:  |  Height:  |  Size: 2.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.8 KiB

After

Width:  |  Height:  |  Size: 2.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.1 KiB

After

Width:  |  Height:  |  Size: 2.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.8 KiB

After

Width:  |  Height:  |  Size: 2.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.1 KiB

After

Width:  |  Height:  |  Size: 2.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.1 KiB

After

Width:  |  Height:  |  Size: 2.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.8 KiB

After

Width:  |  Height:  |  Size: 2.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.8 KiB

After

Width:  |  Height:  |  Size: 2.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.8 KiB

After

Width:  |  Height:  |  Size: 2.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.8 KiB

After

Width:  |  Height:  |  Size: 2.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.1 KiB

After

Width:  |  Height:  |  Size: 2.8 KiB

View File

Before

Width:  |  Height:  |  Size: 1.5 KiB

After

Width:  |  Height:  |  Size: 1.5 KiB

View File

Before

Width:  |  Height:  |  Size: 1.5 KiB

After

Width:  |  Height:  |  Size: 1.5 KiB

View File

Before

Width:  |  Height:  |  Size: 2.2 KiB

After

Width:  |  Height:  |  Size: 2.2 KiB

View File

Before

Width:  |  Height:  |  Size: 2.2 KiB

After

Width:  |  Height:  |  Size: 2.2 KiB

View File

Before

Width:  |  Height:  |  Size: 1.5 KiB

After

Width:  |  Height:  |  Size: 1.5 KiB

View File

Before

Width:  |  Height:  |  Size: 1.5 KiB

After

Width:  |  Height:  |  Size: 1.5 KiB

View File

Before

Width:  |  Height:  |  Size: 1.5 KiB

After

Width:  |  Height:  |  Size: 1.5 KiB

View File

Before

Width:  |  Height:  |  Size: 1.5 KiB

After

Width:  |  Height:  |  Size: 1.5 KiB

View File

Before

Width:  |  Height:  |  Size: 2.3 KiB

After

Width:  |  Height:  |  Size: 2.3 KiB

View File

Before

Width:  |  Height:  |  Size: 1.5 KiB

After

Width:  |  Height:  |  Size: 1.5 KiB

View File

Before

Width:  |  Height:  |  Size: 2.2 KiB

After

Width:  |  Height:  |  Size: 2.2 KiB

View File

Before

Width:  |  Height:  |  Size: 1.5 KiB

After

Width:  |  Height:  |  Size: 1.5 KiB

View File

Before

Width:  |  Height:  |  Size: 2.2 KiB

After

Width:  |  Height:  |  Size: 2.2 KiB

View File

Before

Width:  |  Height:  |  Size: 1.5 KiB

After

Width:  |  Height:  |  Size: 1.5 KiB

View File

Before

Width:  |  Height:  |  Size: 1.5 KiB

After

Width:  |  Height:  |  Size: 1.5 KiB

View File

Before

Width:  |  Height:  |  Size: 1.5 KiB

After

Width:  |  Height:  |  Size: 1.5 KiB

View File

Before

Width:  |  Height:  |  Size: 1.5 KiB

After

Width:  |  Height:  |  Size: 1.5 KiB

View File

@@ -28,7 +28,7 @@ class TinyAlphNum : Font {
private val mappingTable = HashMap<Int, Int>()*/
init {
fontSheet = SpriteSheet("./assets/graphics/fonts/cp949.png", W, H)
fontSheet = SpriteSheet("./assets/graphics/fonts/milky.png", W, H)
//chars.forEachIndexed { i, c -> mappingTable[c.toInt()] = i }
}

View File

@@ -2,6 +2,9 @@
Created by minjaesong on 16-09-15.
--]]
-------------
-- ALIASES --
-------------
fs.run = function(p)
local f = fs.open(p, "r")
@@ -11,6 +14,9 @@ end
_G.loadstring = _G.load
_G.print = term.print
--------------
-- HEXUTILS --
--------------

View File

@@ -6,6 +6,7 @@ import li.cil.repack.org.luaj.vm2.lib.TwoArgFunction
import li.cil.repack.org.luaj.vm2.lib.ZeroArgFunction
import net.torvald.terrarum.Terrarum
import net.torvald.terrarum.virtualcomputer.computer.BaseTerrarumComputer
import net.torvald.terrarum.virtualcomputer.luaapi.Term.Companion.checkIBM437
import java.io.*
import java.nio.file.Files
import java.nio.file.Path
@@ -368,7 +369,7 @@ internal class Filesystem(globals: Globals, computer: BaseTerrarumComputer) {
private class FileClassWriteBytes(val fos: FileOutputStream): OneArgFunction() {
override fun call(byteString: LuaValue): LuaValue {
val byteString = byteString.checkjstring()
val byteString = byteString.checkIBM437()
val bytearr = ByteArray(byteString.length, { byteString[it].toByte() })
fos.write(bytearr)
@@ -378,7 +379,7 @@ internal class Filesystem(globals: Globals, computer: BaseTerrarumComputer) {
private class FileClassPrintText(val fw: FileWriter): OneArgFunction() {
override fun call(string: LuaValue): LuaValue {
val text = string.checkjstring()
val text = string.checkIBM437()
fw.write(text)
return LuaValue.NONE
}
@@ -386,7 +387,7 @@ internal class Filesystem(globals: Globals, computer: BaseTerrarumComputer) {
private class FileClassPrintlnText(val fw: FileWriter): OneArgFunction() {
override fun call(string: LuaValue): LuaValue {
val text = string.checkjstring() + "\n"
val text = string.checkIBM437() + "\n"
fw.write(text)
return LuaValue.NONE
}
@@ -415,7 +416,7 @@ internal class Filesystem(globals: Globals, computer: BaseTerrarumComputer) {
private class FileClassReadAllBytes(val path: Path): ZeroArgFunction() {
override fun call(): LuaValue {
val byteArr = Files.readAllBytes(path)
val s: String = java.lang.String(byteArr, "ISO-8859-1").toString()
val s: String = java.lang.String(byteArr, "IBM437").toString()
return LuaValue.valueOf(s)
}
}

View File

@@ -4,6 +4,7 @@ import li.cil.repack.org.luaj.vm2.*
import li.cil.repack.org.luaj.vm2.lib.*
import net.torvald.terrarum.virtualcomputer.terminal.Teletype
import net.torvald.terrarum.virtualcomputer.terminal.Terminal
import java.nio.charset.Charset
/**
* APIs must have some extent of compatibility with ComputerCraft by dan200
@@ -26,6 +27,7 @@ internal class Term(globals: Globals, term: Teletype) {
if (term is Terminal) {
globals["term"]["emitRaw"] = Term.EmitRaw(term)
globals["term"]["emit"] = Term.Emit(term)
globals["term"]["emitString"] = Term.EmitString(term)
globals["term"]["resetColor"] = Term.ResetColour(term)
globals["term"]["resetColour"] = Term.ResetColour(term)
globals["term"]["clear"] = Term.Clear(term)
@@ -44,18 +46,28 @@ internal class Term(globals: Globals, term: Teletype) {
}
}
companion object {
fun LuaValue.checkIBM437(): String {
if (this is LuaString)
return m_bytes.copyOfRange(m_offset, m_length).toString(Charset.forName("ISO-8859-1"))
// it only works if Charset is ISO-8859, despite of the name "IBM437"
else
throw LuaError("bad argument (string expected, got ${this.typename()})")
}
}
class WriteString(val tty: Teletype) : LuaFunction() {
override fun call(p0: LuaValue): LuaValue {
if (tty is Terminal)
tty.writeString(p0.checkjstring())
tty.writeString(p0.checkIBM437())
else
tty.writeChars(p0.checkjstring())
tty.writeChars(p0.checkIBM437())
return LuaValue.NONE
}
override fun call(s: LuaValue, x: LuaValue, y: LuaValue): LuaValue {
if (tty is Terminal)
tty.writeString(s.checkjstring(), x.checkint(), y.checkint())
tty.writeString(s.checkIBM437(), x.checkint(), y.checkint())
else
throw LuaError("couldn't move cursor; TTY is one-dimensional")
return LuaValue.NONE
@@ -65,15 +77,15 @@ internal class Term(globals: Globals, term: Teletype) {
class PrintString(val tty: Teletype) : LuaFunction() {
override fun call(p0: LuaValue): LuaValue {
if (tty is Terminal)
tty.printString(p0.checkjstring())
tty.printString(p0.checkIBM437())
else
tty.printChars(p0.checkjstring())
tty.printChars(p0.checkIBM437())
return LuaValue.NONE
}
override fun call(s: LuaValue, x: LuaValue, y: LuaValue): LuaValue {
if (tty is Terminal)
tty.printString(s.checkjstring(), x.checkint(), y.checkint())
tty.printString(s.checkIBM437(), x.checkint(), y.checkint())
else
throw LuaError("couldn't move cursor; TTY is one-dimensional")
return LuaValue.NONE
@@ -87,16 +99,23 @@ internal class Term(globals: Globals, term: Teletype) {
}
}
class EmitRaw(val term: Terminal) : OneArgFunction() {
override fun call(p0: LuaValue): LuaValue {
term.emitChar(p0.checkint())
class EmitRaw(val term: Terminal) : ThreeArgFunction() {
override fun call(p0: LuaValue, x: LuaValue, y: LuaValue): LuaValue {
term.emitChar(p0.checkint(), x.checkint(), y.checkint())
return LuaValue.NONE
}
}
class Emit(val term: Terminal) : OneArgFunction() {
override fun call(p0: LuaValue): LuaValue {
term.emitChar(p0.checkint().toChar())
class Emit(val term: Terminal) : ThreeArgFunction() {
override fun call(p0: LuaValue, x: LuaValue, y: LuaValue): LuaValue {
term.emitChar(p0.checkint().toChar(), x.checkint(), y.checkint())
return LuaValue.NONE
}
}
class EmitString(val term: Terminal) : ThreeArgFunction() {
override fun call(p0: LuaValue, x: LuaValue, y: LuaValue): LuaValue {
term.emitString(p0.checkIBM437(), x.checkint(), y.checkint())
return LuaValue.NONE
}
}

View File

@@ -93,6 +93,7 @@ open class SimpleTextTerminal(
open protected val colourScreen = if (colour) Color(4, 4, 4) else Color(19, 19, 19)
override fun getColor(index: Int): Color = colours[index]
override fun update(gc: GameContainer, delta: Int) {
@@ -191,14 +192,14 @@ open class SimpleTextTerminal(
/** Emits a bufferChar. Does not move cursor
* It is also not affected by the control sequences; just print them out as symbol */
override fun emitChar(bufferChar: Int) {
screenBuffer.drawBuffer(cursorX, cursorY, bufferChar.toChar())
override fun emitChar(bufferChar: Int, x: Int, y: Int) {
screenBuffer.drawBuffer(x, y, bufferChar.toChar())
}
/** Emits a char. Does not move cursor
* It is also not affected by the control sequences; just print them out as symbol */
override fun emitChar(c: Char) {
screenBuffer.drawBuffer(cursorX, cursorY, c.toInt().and(0xFF).toChar(), colourKey)
override fun emitChar(c: Char, x: Int, y: Int) {
screenBuffer.drawBuffer(x, y, c.toInt().and(0xFF).toChar(), colourKey)
}
/** Prints a char and move cursor accordingly. */
@@ -244,18 +245,21 @@ open class SimpleTextTerminal(
/** Emits a string and move cursor accordingly. */
override fun writeString(s: String, x: Int, y: Int) {
setCursor(x, y)
emitString(s)
val absCursorPos = cursorX + cursorY * width + s.length
setCursor(absCursorPos % width, absCursorPos / width)
for (i in 0..s.length - 1) {
printChar(s[i])
wrap()
}
}
/** Emits a string. Does not move cursor */
override fun emitString(s: String) {
val x = cursorX
val y = cursorY
/** Emits a string, does not affected by control sequences. Does not move cursor */
override fun emitString(s: String, x: Int, y: Int) {
setCursor(x, y)
for (i in 0..s.length - 1)
printChar(s[i])
for (i in 0..s.length - 1) {
emitChar(s[i])
wrap()
}
setCursor(x, y)
}

View File

@@ -39,14 +39,14 @@ interface Terminal : Teletype {
fun setCursor(x: Int, y: Int)
/** Emits a bufferChar. Does not move cursor
* It is also not affected by the control sequences; just print them out as symbol */
fun emitChar(bufferChar: Int)
fun emitChar(bufferChar: Int, x: Int = cursorX, y: Int = cursorY)
/** Emits a char. Does not move cursor
* It is also not affected by the control sequences; just print them out as symbol */
fun emitChar(c: Char)
fun emitChar(c: Char, x: Int = cursorX, y: Int = cursorY)
/** Prints a char and move cursor accordingly. */
override fun printChar(c: Char)
/** Emits a string. Does not move cursor */
fun emitString(s: String)
/** Emits a string, does not affected by control sequences. Does not move cursor */
fun emitString(s: String, x: Int = cursorX, y: Int = cursorY)
/** Emits a string and move cursor accordingly, then do LF */
fun printString(s: String, x: Int = cursorX, y: Int = cursorY)
/** Emits a string and move cursor accordingly. */