-
Notifications
You must be signed in to change notification settings - Fork 92
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
74 changed files
with
2,905 additions
and
1,696 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 0 additions & 47 deletions
47
.../src/main/kotlin/org/worldcubeassociation/tnoodle/server/webscrambles/pdf/BasePdfSheet.kt
This file was deleted.
Oops, something went wrong.
37 changes: 0 additions & 37 deletions
37
...main/kotlin/org/worldcubeassociation/tnoodle/server/webscrambles/pdf/BaseScrambleSheet.kt
This file was deleted.
Oops, something went wrong.
49 changes: 49 additions & 0 deletions
49
.../main/kotlin/org/worldcubeassociation/tnoodle/server/webscrambles/pdf/FewestMovesSheet.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package org.worldcubeassociation.tnoodle.server.webscrambles.pdf | ||
|
||
import org.worldcubeassociation.tnoodle.server.webscrambles.Translate | ||
import org.worldcubeassociation.tnoodle.server.webscrambles.wcif.model.* | ||
import java.util.Locale | ||
|
||
abstract class FewestMovesSheet( | ||
val scramble: Scramble, | ||
val totalAttemptsNum: Int, | ||
override val scrambleSetId: Int, | ||
competitionTitle: String, | ||
activityCode: ActivityCode, | ||
hasGroupId: Boolean, | ||
locale: Locale, | ||
watermark: String? | ||
) : ScrambleSheet(competitionTitle, activityCode, hasGroupId, locale, watermark) { | ||
override val scrambles: List<Scramble> | ||
get() = listOfNotNull(scramble) | ||
|
||
val currentAttemptNum: Int | ||
get() = activityCode.attemptNumber?.plus(1) ?: 1 | ||
|
||
val localEventTitle: String | ||
get() = Translate("fmc.event", locale) | ||
|
||
val attemptDetails: String | ||
get() = activityCode.copyParts(attemptNumber = null) // FMC is split per attempt so we count scrambleXofY instead | ||
.compileTitleString(locale, includeEvent = false, includeGroupId = hasGroupId) | ||
|
||
val activityTitle: String | ||
get() = "$localEventTitle $attemptDetails".trim() | ||
|
||
val scrambleXOfY | ||
get(): String { | ||
val substitutions = mapOf( | ||
"scrambleIndex" to currentAttemptNum.toString(), | ||
"scrambleCount" to totalAttemptsNum.toString() | ||
) | ||
|
||
return Translate("fmc.scrambleXofY", locale, substitutions) | ||
} | ||
|
||
companion object { | ||
const val MOVE_BARS_PER_LINE = 10 | ||
const val MOVE_BAR_LINES = 8 | ||
|
||
const val WCA_MAX_MOVES_FMC = MOVE_BARS_PER_LINE * MOVE_BAR_LINES | ||
} | ||
} |
114 changes: 114 additions & 0 deletions
114
...rc/main/kotlin/org/worldcubeassociation/tnoodle/server/webscrambles/pdf/FmcCutoutSheet.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
package org.worldcubeassociation.tnoodle.server.webscrambles.pdf | ||
|
||
import org.worldcubeassociation.tnoodle.server.webscrambles.Translate | ||
import org.worldcubeassociation.tnoodle.server.webscrambles.pdf.model.dsl.DocumentBuilder | ||
import org.worldcubeassociation.tnoodle.server.webscrambles.pdf.model.dsl.PageBuilder | ||
import org.worldcubeassociation.tnoodle.server.webscrambles.pdf.model.properties.Alignment | ||
import org.worldcubeassociation.tnoodle.server.webscrambles.pdf.model.properties.Drawing | ||
import org.worldcubeassociation.tnoodle.server.webscrambles.pdf.model.properties.Font | ||
import org.worldcubeassociation.tnoodle.server.webscrambles.pdf.model.properties.Paper.inchesToPixel | ||
import org.worldcubeassociation.tnoodle.server.webscrambles.pdf.model.properties.Paper.pixelsToInch | ||
import org.worldcubeassociation.tnoodle.server.webscrambles.wcif.model.* | ||
import java.util.* | ||
|
||
class FmcCutoutSheet( | ||
scramble: Scramble, | ||
activityCode: ActivityCode, | ||
scrambleSetId: Int, | ||
locale: Locale, | ||
totalAttemptsNum: Int, | ||
competitionTitle: String, | ||
hasGroupId: Boolean, | ||
watermark: String? = null | ||
) : FewestMovesSheet(scramble, totalAttemptsNum, scrambleSetId, competitionTitle, activityCode, hasGroupId, locale, watermark) { | ||
override fun DocumentBuilder.writeContents() { | ||
page { | ||
setVerticalMargins(10) | ||
setHorizontalMargins(20) | ||
|
||
addFmcScrambleCutoutSheet() | ||
} | ||
} | ||
|
||
private fun PageBuilder.addFmcScrambleCutoutSheet() { | ||
val scrambleSuffix = scrambleXOfY | ||
.takeIf { totalAttemptsNum > 1 }.orEmpty() | ||
|
||
val title = "$activityTitle $scrambleSuffix".trim() | ||
|
||
val baseFont = Font.fontForLocale(Translate.DEFAULT_LOCALE) | ||
val localFont = Font.fontForLocale(locale) | ||
|
||
val paddingHeightPenalty = SCRAMBLES_PER_SHEET * 2 * Drawing.Padding.DEFAULT | ||
|
||
val actualWidthIn = size.widthIn - (marginLeft + marginRight).pixelsToInch | ||
val actualHeightIn = size.heightIn - (marginTop + marginBottom).pixelsToInch - | ||
paddingHeightPenalty.pixelsToInch | ||
|
||
val scramblerPreferredSize = scramblingPuzzle.preferredSize | ||
val scramblerWidthToHeight = scramblerPreferredSize.width.toFloat() / scramblerPreferredSize.height | ||
|
||
table(2) { | ||
// see GeneralScrambleSheet to figure out what this is about (: | ||
val relativeHeight = actualHeightIn / actualWidthIn | ||
val relHeightPerScramble = relativeHeight / SCRAMBLES_PER_SHEET | ||
|
||
val scrambleWidth = relHeightPerScramble * scramblerWidthToHeight | ||
|
||
// as we're always printing more than 1 scramble per sheet, | ||
// naively assume that fullWidth < 1 | ||
val textWidth = 1 - scrambleWidth | ||
relativeWidths = listOf(textWidth, scrambleWidth) | ||
|
||
border = Drawing.Border.ROWS_ONLY | ||
stroke = Drawing.Stroke.DASHED | ||
|
||
repeat(SCRAMBLES_PER_SHEET) { | ||
row { | ||
verticalAlignment = Alignment.Vertical.MIDDLE | ||
|
||
cell { | ||
paragraph { | ||
leading = 1f | ||
|
||
// TODO this is a hack to prevent some margins overlapping | ||
// TODO magic number factor | ||
val scaledTextWidth = textWidth * 0.98f | ||
|
||
line(competitionTitle) { | ||
fontName = baseFont | ||
|
||
val relHeightForCompName = relHeightPerScramble / 8 | ||
setOptimalOneLineFontSize(relHeightForCompName, scaledTextWidth, actualWidthIn) | ||
} | ||
line(title) { | ||
fontName = localFont | ||
|
||
val relHeightForTitle = relHeightPerScramble / 4 | ||
setOptimalOneLineFontSize(relHeightForTitle, scaledTextWidth, actualWidthIn) | ||
} | ||
line(scramble.scrambleString) { | ||
fontName = baseFont | ||
|
||
val relHeightForScrambleString = relHeightPerScramble / 2 | ||
setOptimalOneLineFontSize(relHeightForScrambleString, scaledTextWidth, actualWidthIn) | ||
} | ||
} | ||
} | ||
|
||
cell { | ||
padding = 2 * Drawing.Padding.DEFAULT | ||
horizontalAlignment = Alignment.Horizontal.CENTER | ||
|
||
val scrambleWidthPx = (scrambleWidth * actualWidthIn).inchesToPixel | ||
svgScrambleImage(scramble.scrambleString, scrambleWidthPx) | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
companion object { | ||
val SCRAMBLES_PER_SHEET = 8 | ||
} | ||
} |
19 changes: 0 additions & 19 deletions
19
...otlin/org/worldcubeassociation/tnoodle/server/webscrambles/pdf/FmcGenericSolutionSheet.kt
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.