Skip to content

Commit

Permalink
Move TeX header outside of user input, get and use that resource
Browse files Browse the repository at this point in the history
Add output directory creation to pre-processing stage
Idiomatic PrintWriter section
  • Loading branch information
James authored and James committed May 5, 2019
1 parent e3c8ffe commit fec7248
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 14 deletions.
18 changes: 7 additions & 11 deletions src/main/kotlin/org/idiosapps/BuilderPipeline.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,18 @@ class BuilderPipeline : Task<Parent>() {

var languageUsed = "mandarin"

OSUtils.tryMakeOutputDir() // Java will only make a new file if the parent folder exists (on Windows anyway)
val outputStoryTeXWriter = PrintWriter(Filenames.outputTexFilename, "UTF-8")

val vocab = VocabUtils.splitIntoParts(Filenames.inputVocabFilename)
val names = VocabUtils.splitIntoParts(Filenames.inputKeyNamesFilename)

PrintWriter(Filenames.outputTexFilename, "UTF-8").use { texWriter ->
TexUtils.copyToTex(texWriter, Filenames.inputHeaderResource)
TexUtils.copyToTex(texWriter, Filenames.inputTitleFilename)
TexUtils.copyToTex(texWriter, Filenames.inputStoryFilename)

TexUtils.copyToTex(outputStoryTeXWriter, Filenames.inputHeaderFilename)
TexUtils.copyToTex(outputStoryTeXWriter, Filenames.inputTitleFilename)
TexUtils.copyToTex(outputStoryTeXWriter, Filenames.inputStoryFilename)

SummaryPageWriter.writeVocabSection(outputStoryTeXWriter, vocab)
// todo WriteSummaryPage.writeTexGrammar
SummaryPageWriter.writeVocabSection(texWriter, vocab) // TODO add summary / grammar pages too

outputStoryTeXWriter.append("\\end{document}")
outputStoryTeXWriter.close()
texWriter.append("\\end{document}")
}

PDFUtils.xelatexToPDF()

Expand Down
2 changes: 2 additions & 0 deletions src/main/kotlin/org/idiosapps/FXMLController.kt
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class FXMLController {
try { // first check dependencies & inputs - have a good idea of what to expect
OSUtils.hasProgram(PDFTEX)
OSUtils.hasProgram(XETEX)
OSUtils.tryMakeOutputDir() // Java will only make a new file if the parent folder exists (on Windows anyway)

Filenames.checkInputs() // just check files exist
clearInputStateLabels()
Expand All @@ -51,6 +52,7 @@ class FXMLController {
}
}

// Start another thread with the real processing, so the UI doesn't freeze
private fun startBookBuildPipeline() {
val task: Task<Parent> = BuilderPipeline()
progressBar.progressProperty().bind(task.progressProperty())
Expand Down
4 changes: 2 additions & 2 deletions src/main/kotlin/org/idiosapps/Filenames.kt
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package org.idiosapps

import java.io.File
import java.net.URL

class Filenames {
companion object {
val inputPrefix: String = "./input/"
val outputPrefix: String = "./output/"

val inputHeaderFilename: String = inputPrefix + "header"
val inputHeaderResource: URL = this::class.java.classLoader.getResource("org.idiosapps/texHeader")
val inputTitleFilename: String = inputPrefix + "title"
val inputStoryFilename: String = inputPrefix + "story"

Expand All @@ -19,7 +20,6 @@ class Filenames {

fun checkInputs() {
val inputArray = arrayListOf(
inputHeaderFilename,
inputTitleFilename,
inputStoryFilename,
inputVocabFilename,
Expand Down
11 changes: 11 additions & 0 deletions src/main/kotlin/org/idiosapps/TexUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package org.idiosapps

import java.io.File
import java.io.PrintWriter
import java.net.URL
import java.util.*

class TexUtils {
Expand Down Expand Up @@ -47,5 +48,15 @@ class TexUtils {
}
scanner.close()
}

fun copyToTex(outputStoryWriter: PrintWriter, inputResource: URL) {
val resourceFile = File(inputResource.toURI())

Scanner(resourceFile, "UTF-8").use { scanner ->
while (scanner.hasNextLine()) {
outputStoryWriter.println(scanner.nextLine())
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
% Add the ability to write pinyin with tones
\usepackage{xeCJK}
\usepackage{xpinyin}
% Add the ability to create fancy headers and footers
% Add the ability to create fancy headers and pageFooters
\usepackage{fancyhdr}
% Add the ability to use Lorem Ipsum placeholder text
\usepackage{lipsum}
Expand Down

0 comments on commit fec7248

Please sign in to comment.