Skip to content

Commit

Permalink
Print localised FMC information in correct font
Browse files Browse the repository at this point in the history
  • Loading branch information
gregorbg committed Apr 3, 2021
1 parent 13db2ba commit 9ba6d8d
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,20 +47,31 @@ class FmcScrambleCutoutSheet(scrambleSet: ScrambleSet, activityCode: ActivityCod
val scrambleSuffix = Translate.translate("fmc.scrambleXofY", locale, substitutions)
.takeIf { expectedAttemptNum > 1 } ?: ""

val attemptTitle = activityCode.compileTitleString(locale, includeGroupID = hasGroupID).trim()
val title = "$competitionTitle - $attemptTitle $scrambleSuffix"
val eventTitle = Translate.translate("fmc.event", locale)
val attemptDetails = activityCode.compileTitleString(locale, includeEvent = false, includeGroupID = hasGroupID)
val attemptTitle = "$eventTitle $attemptDetails".trim()

val title = "$attemptTitle $scrambleSuffix"

val font = Font(BASE_FONT, FONT_SIZE / 2)
val localBaseFont = FontUtil.getFontForLocale(locale)
val localFont = Font(localBaseFont, FONT_SIZE)

// empty strings for space above and below
val textList = listOf("", title, scramble, "")
val alignList = List(textList.size) { Element.ALIGN_LEFT }
val textList = listOf(
"" to font,
competitionTitle to font,
title to localFont,
scramble to localFont,
"" to font)

val paddedTitleItems = textList.zip(alignList)
val alignList = List(textList.size) { Element.ALIGN_LEFT }

val font = Font(BASE_FONT, FONT_SIZE)
val paddedTitleItems = textList.zipTriple(alignList)

for (i in 0 until SCRAMBLES_PER_SHEET) {
val rect = Rectangle(LEFT.toFloat(), (top - i * availableScrambleHeight).toFloat(), (right - dim.width - SPACE_SCRAMBLE_IMAGE).toFloat(), (top - (i + 1) * availableScrambleHeight).toFloat())
directContent.populateRect(rect, paddedTitleItems, font)
directContent.populateRect(rect, paddedTitleItems)

directContent.addImage(Image.getInstance(tp), dim.width.toDouble(), 0.0, 0.0, dim.height.toDouble(), (right - dim.width).toDouble(), top.toDouble() - (i + 1) * availableScrambleHeight + (availableScrambleHeight - dim.getHeight()) / 2)

Expand All @@ -82,5 +93,9 @@ class FmcScrambleCutoutSheet(scrambleSet: ScrambleSet, activityCode: ActivityCod
val FONT_SIZE = 20f

val SCRAMBLES_PER_SHEET = 8

private fun <A,B,C> Iterable<Pair<A,B>>.zipTriple(other: Iterable<C>): List<Triple<A,B,C>> {
return zip(other).map { Triple(it.first.first, it.first.second, it.second) }
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -158,14 +158,17 @@ open class FmcSolutionSheet(scrambleSet: ScrambleSet, activityCode: ActivityCode
val gradeRect = Rectangle((competitorInfoLeft + margin).toFloat(), competitorInfoBottom.toFloat(), (right - margin).toFloat(), gradeBottom.toFloat())
val scrambleImageRect = Rectangle((competitorInfoLeft + margin).toFloat(), gradeBottom.toFloat(), (right - margin).toFloat(), scrambleBorderTop.toFloat())

cb.fitAndShowText(Translate.translate("fmc.event", locale), titleRect, titleFont, Element.ALIGN_CENTER)
val localEventTitle = Translate.translate("fmc.event", locale)
cb.fitAndShowText(localEventTitle, titleRect, titleFont, Element.ALIGN_CENTER)

// Both competitor com competition details
val compDetailItems = mutableListOf<Pair<String, Int>>()

if (withScramble) {
val activityTitle = activityCode.copyParts(attemptNumber = null)
.compileTitleString(locale, includeGroupID = hasGroupID)
val activityTitleRaw = activityCode.copyParts(attemptNumber = null)
.compileTitleString(locale, includeEvent = false, includeGroupID = hasGroupID)

val activityTitle = "$localEventTitle $activityTitleRaw"

compDetailItems.add(competitionTitle to Element.ALIGN_CENTER)
compDetailItems.add(activityTitle to Element.ALIGN_CENTER)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ object PdfDrawUtil {

for ((i, content) in itemsWithAlignment.withIndex()) {
val height = slotHeights.subList(0, i).sum()
val proportionalFontSize = slotHeights[i]
val proportionalFontSize = -slotHeights[i]

val temp = Rectangle(rect.left, rect.bottom + height - proportionalFontSize, rect.right, rect.bottom + height)
fitAndShowText(content.first, temp, content.second, content.third, leadingMultiplier)
Expand Down

0 comments on commit 9ba6d8d

Please sign in to comment.