feat: fegyver in PDF (phase 1)

This commit is contained in:
2023-10-18 23:08:18 +02:00
parent 1a0c07f051
commit bbfadbf43e
9 changed files with 420 additions and 322 deletions
+13 -7
View File
@@ -1,12 +1,18 @@
# Getting Started with Create React App
# KéM karakter app
Kard és Mágia Karakter alkotó alkalmazás
Please excuse the Hungish, the domain language of KéM is hungarian, but the domain language of programming is english, which created this monster.
## Getting Started with Create React App
This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app).
## Available Scripts
### Available Scripts
In the project directory, you can run:
### `npm start`
#### `yarn start`
Runs the app in the development mode.\
Open [http://localhost:3000](http://localhost:3000) to view it in the browser.
@@ -14,12 +20,12 @@ Open [http://localhost:3000](http://localhost:3000) to view it in the browser.
The page will reload if you make edits.\
You will also see any lint errors in the console.
### `npm test`
#### `yarn test`
Launches the test runner in the interactive watch mode.\
See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information.
### `npm run build`
#### `yarn run build`
Builds the app for production to the `build` folder.\
It correctly bundles React in production mode and optimizes the build for the best performance.
@@ -29,7 +35,7 @@ Your app is ready to be deployed!
See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information.
### `npm run eject`
#### `yarn run eject`
**Note: this is a one-way operation. Once you `eject`, you cant go back!**
@@ -39,7 +45,7 @@ Instead, it will copy all the configuration files and the transitive dependencie
You dont have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldnt feel obligated to use this feature. However we understand that this tool wouldnt be useful if you couldnt customize it when you are ready for it.
## Learn More
### Learn More
You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started).
+9
View File
@@ -1,5 +1,6 @@
import pancelok from './pancel.json'
import pajzsok from './pajzs.json'
import fegyverek from './fegyver.json'
export type PancelType = 'konnyu' | 'kozepes' | 'nehez'
@@ -87,4 +88,12 @@ export function GetPajzs(id?: string): Pajzs | undefined {
}
const filtered = pajzsok['pajzs'].filter(p => p.ID === id) as Pajzs[]
return filtered.length > 0 ? filtered[0] : undefined
}
export function GetFegyver(id: string): Fegyver | undefined {
return fegyverek.fegyverek.find(f => f.ID === id) as Fegyver | undefined
}
export function GetFegyverek(ids: string[]): Fegyver[] {
return ids.map(GetFegyver).filter(x => x != null).map(x => x as Fegyver)
}
+10 -313
View File
@@ -1,164 +1,13 @@
import {KarakterPdfView, KepzettsegPdfView} from "./karakter_pdf_view";
import {PDFDocument, PDFFont, PDFPage, rgb} from "pdf-lib";
import {PDFDocument, rgb} from "pdf-lib";
import fontkit from '@pdf-lib/fontkit'
import {SignedNumberToText} from "../components/Helpers";
import {KarakterTulajdonsagok, Modifier} from "../domain-models/tulajdonsag";
import download from "downloadjs";
function drawTulajdonsagok(page: PDFPage, tulajdonsagok: KarakterTulajdonsagok, fontSizeBase: number, pdfFont: PDFFont) {
page.drawText(tulajdonsagok.t_ero.toString(), {
x: 130,
y: 613,
size: fontSizeBase * 2,
font: pdfFont,
color: rgb(0, 0, 0),
})
page.drawText(SignedNumberToText(Modifier(tulajdonsagok.t_ero)), {
x: 176,
y: 613,
size: fontSizeBase * 2,
font: pdfFont,
color: rgb(0, 0, 0),
})
page.drawText(tulajdonsagok.t_ugy.toString(), {
x: 130,
y: 580,
size: fontSizeBase * 2,
font: pdfFont,
color: rgb(0, 0, 0),
})
page.drawText(SignedNumberToText(Modifier(tulajdonsagok.t_ugy)), {
x: 176,
y: 580,
size: fontSizeBase * 2,
font: pdfFont,
color: rgb(0, 0, 0),
})
page.drawText(tulajdonsagok.t_egs.toString(), {
x: 130,
y: 547,
size: fontSizeBase * 2,
font: pdfFont,
color: rgb(0, 0, 0),
})
page.drawText(SignedNumberToText(Modifier(tulajdonsagok.t_egs)), {
x: 176,
y: 547,
size: fontSizeBase * 2,
font: pdfFont,
color: rgb(0, 0, 0),
})
page.drawText(tulajdonsagok.t_int.toString(), {
x: 130,
y: 515,
size: fontSizeBase * 2,
font: pdfFont,
color: rgb(0, 0, 0),
})
page.drawText(SignedNumberToText(Modifier(tulajdonsagok.t_int)), {
x: 176,
y: 515,
size: fontSizeBase * 2,
font: pdfFont,
color: rgb(0, 0, 0),
})
page.drawText(tulajdonsagok.t_bol.toString(), {
x: 130,
y: 482,
size: fontSizeBase * 2,
font: pdfFont,
color: rgb(0, 0, 0),
})
page.drawText(SignedNumberToText(Modifier(tulajdonsagok.t_bol)), {
x: 176,
y: 482,
size: fontSizeBase * 2,
font: pdfFont,
color: rgb(0, 0, 0),
})
page.drawText(tulajdonsagok.t_kar.toString(), {
x: 130,
y: 449,
size: fontSizeBase * 2,
font: pdfFont,
color: rgb(0, 0, 0),
})
page.drawText(SignedNumberToText(Modifier(tulajdonsagok.t_kar)), {
x: 176,
y: 449,
size: fontSizeBase * 2,
font: pdfFont,
color: rgb(0, 0, 0),
})
}
function drawMentok(page: PDFPage, karakter: KarakterPdfView, fontSizeBase: number, pdfFont: PDFFont) {
const mentokAlap = karakter.MentokAlap
page.drawText(SignedNumberToText(mentokAlap.kitartas), {
x: 435,
y: 613,
size: fontSizeBase,
font: pdfFont,
color: rgb(0, 0, 0),
})
page.drawText(SignedNumberToText(mentokAlap.reflex), {
x: 435,
y: 580,
size: fontSizeBase,
font: pdfFont,
color: rgb(0, 0, 0),
})
page.drawText(SignedNumberToText(mentokAlap.akaratero), {
x: 435,
y: 547,
size: fontSizeBase,
font: pdfFont,
color: rgb(0, 0, 0),
})
page.drawText(SignedNumberToText(Modifier(karakter.Tulajdonsagok.t_egs)), {
x: 475,
y: 613,
size: fontSizeBase,
font: pdfFont,
color: rgb(0, 0, 0),
})
page.drawText(SignedNumberToText(Modifier(karakter.Tulajdonsagok.t_ugy)), {
x: 475,
y: 580,
size: fontSizeBase,
font: pdfFont,
color: rgb(0, 0, 0),
})
page.drawText(SignedNumberToText(Modifier(karakter.Tulajdonsagok.t_bol)), {
x: 475,
y: 547,
size: fontSizeBase,
font: pdfFont,
color: rgb(0, 0, 0),
})
const mentok = karakter.MentokModositokkal
page.drawText(SignedNumberToText(mentok.kitartas), {
x: 515,
y: 613,
size: fontSizeBase,
font: pdfFont,
color: rgb(0, 0, 0),
})
page.drawText(SignedNumberToText(mentok.reflex), {
x: 515,
y: 580,
size: fontSizeBase,
font: pdfFont,
color: rgb(0, 0, 0),
})
page.drawText(SignedNumberToText(mentok.akaratero), {
x: 515,
y: 547,
size: fontSizeBase,
font: pdfFont,
color: rgb(0, 0, 0),
})
}
import {DrawTulajdonsagok} from "./tulajdonsagok.pdf";
import {DrawMentok} from "./mentok.pdf";
import {DrawMagic} from "./magic.pdf";
import {DrawMasodlagosErtekek} from './masodlagos_ertekek.pdf'
import {DrawOsztalySpecialsPage} from './osztaly_specials.pdf'
function drawBaseInfo(karakter: KarakterPdfView, draw: (text: string, x : number ,y: number, scale: number) => void) {
draw(karakter.Name, 60, 710, 1)
@@ -188,35 +37,6 @@ function DrawFelszereles(draw: (text: string, x: number, y:number) => void, fels
}
}
function DrawMagic(page: PDFPage, fontSizeBase: number, pdfFont: PDFFont, napiVarazslatok: number[], varazsMentokNF: number[]){
for(let i = 0; i < 6; i++) {
const y = 247 - (i*18)
page.drawText(i.toString(), {
x: 210,
y: y,
size: fontSizeBase,
font: pdfFont,
color: rgb(0, 0, 0),
})
if (i < napiVarazslatok.length) {
page.drawText(napiVarazslatok[i].toString(), {
x: 242,
y: y,
size: fontSizeBase,
font: pdfFont,
color: rgb(0, 0, 0),
})
page.drawText(varazsMentokNF[i].toString(), {
x: 269,
y: y,
size: fontSizeBase,
font: pdfFont,
color: rgb(0, 0, 0),
})
}
}
}
export async function CreatePDF(karakter: KarakterPdfView) {
const existingPdfBytes = await fetch('/km_karakterlap_hysteria_1.2.pdf').then(res => res.arrayBuffer())
@@ -242,94 +62,11 @@ export async function CreatePDF(karakter: KarakterPdfView) {
drawBaseInfo(karakter, drawText);
drawTulajdonsagok(page, karakter.Tulajdonsagok, fontSizeBase, pdfFont);
DrawTulajdonsagok(page, karakter.Tulajdonsagok, fontSizeBase, pdfFont);
page.drawText(karakter.Mozgas.toString(), {
x: 162,
y: 416,
size: fontSizeBase * 2,
font: pdfFont,
color: rgb(0, 0, 0),
})
page.drawText(SignedNumberToText(karakter.Kezdemenyezes), {
x: 505,
y: 416,
size: fontSizeBase * 2,
font: pdfFont,
color: rgb(0, 0, 0),
})
page.drawText(karakter.HP.toString(), {
x: 318,
y: 517,
size: fontSizeBase * 1.5,
font: pdfFont,
color: rgb(0, 0, 0),
})
page.drawText(karakter.VO.toString(), {
x: 368,
y: 495,
size: fontSizeBase * 3,
font: pdfFont,
color: rgb(0, 0, 0),
})
page.drawText(karakter.PancelVO.toString(), {
x: 512,
y: 515,
size: fontSizeBase * 2,
font: pdfFont,
color: rgb(0, 0, 0),
})
page.drawText(karakter.PajzsVO.toString(), {
x: 512,
y: 482,
size: fontSizeBase * 2,
font: pdfFont,
color: rgb(0, 0, 0),
})
const kozelharciTB = karakter.KozelharciTB.map(SignedNumberToText).join("/")
DrawMasodlagosErtekek(page, karakter, fontSizeBase, pdfFont);
function getFontSize(length: number): number {
switch (length) {
case 1:
case 2:
return 24;
case 3:
return 18;
case 4:
return 14;
case 5:
return 11;
case 6:
return 9;
case 7:
return 8;
default:
return 6;
}
}
function getYOffset(length: number): number {
return Math.min(length-2, 6);
}
const kozelHarciFontSize = getFontSize(kozelharciTB.length)
page.drawText(kozelharciTB, {
x: kozelharciTB.length > 4 ? 256 : 258,
y: 383 + getYOffset(kozelharciTB.length),
size: kozelHarciFontSize,
font: pdfFont,
color: rgb(0, 0, 0),
})
const celzoTB = karakter.CelzoTB.map(SignedNumberToText).join("/")
const celzoFontSize = getFontSize(celzoTB.length)
page.drawText(celzoTB, {
x: celzoTB.length > 4 ? 343 : 346,
y: 383 + getYOffset(celzoTB.length),
size: celzoFontSize,
font: pdfFont,
color: rgb(0, 0, 0),
})
drawMentok(page, karakter, fontSizeBase, pdfFont);
DrawMentok(page, karakter, fontSizeBase, pdfFont);
DrawKepzettsegek(drawText, karakter.Kepzettsegek, 337);
const nextKepzettsegFrom = 337 - (karakter.Kepzettsegek.length * 18)
@@ -340,49 +77,9 @@ export async function CreatePDF(karakter: KarakterPdfView) {
DrawMagic(page, fontSizeBase, pdfFont, karakter.NapiMemorizalhatoVarazslatok, karakter.VarazslatMentokNF)
const secondPage = pdfDoc.addPage()
DrawSecondPage(secondPage, pdfFont, karakter)
DrawOsztalySpecialsPage(secondPage, pdfFont, karakter)
const pdfBytes = await pdfDoc.save();
download(pdfBytes, karakter.Name + ".pdf", "application/pdf");
}
function DrawSecondPage(page: PDFPage, font: PDFFont, karakter: KarakterPdfView){
const baseFontSize = 12
const titleFontSize = baseFontSize * 3
const pageCenterX = page.getWidth()/2
const titleWidth = font.widthOfTextAtSize(karakter.Osztaly, titleFontSize)
const titleX = pageCenterX - (titleWidth / 2)
page.drawText(karakter.Osztaly, {
x: titleX,
y: 770,
size: titleFontSize,
font: font,
color: rgb(0, 0, 0),
})
let rows = 0
// const margin = 30
// const textWidth = page.getWidth() - 2*margin;
for (let i = 0; i < karakter.OsztalySkills.length; i++) {
const skill = karakter.OsztalySkills[i];
page.drawText(skill.Name, {
x: 30,
y: 720 - rows,
size: baseFontSize,
font: font,
color: rgb(0, 0, 0),
})
page.drawText(skill.Description, {
x: 30,
y: 700 - rows,
size: baseFontSize,
font: font,
lineHeight: 16,
color: rgb(0, 0, 0),
// maxWidth: textWidth,
// wordBreaks: [' ', '-']
})
// rows += Math.ceil(font.widthOfTextAtSize(skill.Description, baseFontSize)/textWidth)*20 + 30
rows += skill.Description.split('\n').length*16 + 30
}
}
+7 -2
View File
@@ -16,7 +16,7 @@ import {CelzoTB, KozelharciTB} from "../domain-models/tamadas_bonusz";
import {KarakterInputs} from "../domain-models/karakter";
import {NapiVarazslatok, CalculateVarazslatMentokNF} from "../domain-models/memorizalt_varazslatok";
import {GetJellem} from "../domain-models/jellem";
import {GetPancel, GetPajzs} from '../domain-models/felszereles'
import {GetPancel, GetPajzs, Fegyver, GetFegyverek} from '../domain-models/felszereles'
export interface KepzettsegPdfView {
KepzettsegName: string
@@ -51,6 +51,7 @@ export interface KarakterPdfView {
Felszereles: string[]
PancelVO: number
PajzsVO: number
Fegyverek: Fegyver[]
}
export function KarakterInputToPdfView(karakter: KarakterInputs): KarakterPdfView {
@@ -68,6 +69,9 @@ export function KarakterInputToPdfView(karakter: KarakterInputs): KarakterPdfVie
const NapiMemorizalhatoVarazslatok = NapiVarazslatok(karakter)
const VarazslatMentokNF = CalculateVarazslatMentokNF(karakter)
const fegyverek = GetFegyverek(karakter.felszereles.fegyverIDk)
const felszereles = [ pancel?.Name, pajzs?.Name, ...fegyverek.filter(f => f.ID !== 'okol').map(f => f.Name.includes('és') ? f.Name.split(' ')[0] : f.Name) ].filter(x => !!x) as string[]
return {
Faj: FajLabel(karakter.faj),
@@ -97,9 +101,10 @@ export function KarakterInputToPdfView(karakter: KarakterInputs): KarakterPdfVie
NapiMemorizalhatoVarazslatok,
VarazslatMentokNF,
Felszereles: [pancel?.Name, pajzs?.Name].filter(x => !!x) as string[],
Felszereles: felszereles,
PajzsVO: pajzs?.VO ?? 0,
PancelVO: pancel?.VO ?? 0,
Fegyverek: fegyverek,
}
}
+30
View File
@@ -0,0 +1,30 @@
import {PDFFont, PDFPage, rgb} from "pdf-lib";
export function DrawMagic(page: PDFPage, fontSizeBase: number, pdfFont: PDFFont, napiVarazslatok: number[], varazsMentokNF: number[]){
for(let i = 0; i < 6; i++) {
const y = 247 - (i*18)
page.drawText(i.toString(), {
x: 210,
y: y,
size: fontSizeBase,
font: pdfFont,
color: rgb(0, 0, 0),
})
if (i < napiVarazslatok.length) {
page.drawText(napiVarazslatok[i].toString(), {
x: 242,
y: y,
size: fontSizeBase,
font: pdfFont,
color: rgb(0, 0, 0),
})
page.drawText(varazsMentokNF[i].toString(), {
x: 269,
y: y,
size: fontSizeBase,
font: pdfFont,
color: rgb(0, 0, 0),
})
}
}
}
+147
View File
@@ -0,0 +1,147 @@
import {PDFFont, PDFPage} from "pdf-lib";
import {KarakterPdfView} from "./karakter_pdf_view";
import {SignedNumberToText} from "../components/Helpers";
function drawFegyverek(karakter: KarakterPdfView, pdfFont: PDFFont, fontSizeBase: number, page: PDFPage) {
const startFrom = 337
for (let i = 0; i < karakter.Fegyverek.length && i < 3; i++) {
const fegyver = karakter.Fegyverek[i];
const simplifiedName = fegyver.Name.includes('és') ? fegyver.Name.split(' ')[0] : fegyver.Name
const size = fitTextInWidth(pdfFont, simplifiedName, fontSizeBase, 60)
page.drawText(simplifiedName, {
x: 200,
y: startFrom - (i * 18) + ((18 - pdfFont.heightAtSize(size)) / 3),
size: size,
font: pdfFont,
})
const tb = SignedNumberToText(fegyver.Type === 'kozelharci' ? karakter.KozelharciTB[0] : karakter.CelzoTB[0])
page.drawText(tb, {
x: 265,
y: startFrom - (i * 18),
size: fontSizeBase,
font: pdfFont,
})
const damage = `${fegyver.NumberOfDamageDice > 1 ? fegyver.NumberOfDamageDice.toString() : ''}d${fegyver.DamageDice}${fegyver.Type === 'kozelharci' && karakter.TulajdonsagModositok.t_ero > 0 ? ` + ${karakter.TulajdonsagModositok.t_ero}` : ''}`
const damageSize = fitTextInWidth(pdfFont, damage, fontSizeBase, 24)
if (damageSize !== fontSizeBase) {
console.log('font size: ', damageSize)
console.log('width of text: ', pdfFont.widthOfTextAtSize(damage, damageSize))
}
page.drawText(damage, {
x: 291,
y: startFrom - (i * 18) + ((18 - pdfFont.heightAtSize(damageSize)) / 3),
size: damageSize,
font: pdfFont,
})
const crit = `${fegyver.CritRangeStart < 20 ? `${fegyver.CritRangeStart}-20` : '20'} x${fegyver.CritMultiplier}`
const critSize = fitTextInWidth(pdfFont, crit, fontSizeBase, 35)
page.drawText(crit, {
x: 318,
y: startFrom - (i * 18) + ((18 - pdfFont.heightAtSize(critSize)) / 3),
size: critSize,
font: pdfFont,
})
const range = fegyver.Range === 0 ? '-' : fegyver.Range.toString()
page.drawText(range, {
x: 360,
y: startFrom - (i * 18),
size: fontSizeBase,
font: pdfFont,
})
}
}
export function DrawMasodlagosErtekek(
page: PDFPage,
karakter: KarakterPdfView,
fontSizeBase: number,
pdfFont: PDFFont)
{
page.drawText(karakter.Mozgas.toString(), {
x: 162,
y: 416,
size: fontSizeBase * 2,
font: pdfFont,
})
page.drawText(SignedNumberToText(karakter.Kezdemenyezes), {
x: 505,
y: 416,
size: fontSizeBase * 2,
font: pdfFont,
})
page.drawText(karakter.HP.toString(), {
x: 318,
y: 517,
size: fontSizeBase * 1.5,
font: pdfFont,
})
page.drawText(karakter.VO.toString(), {
x: 368,
y: 495,
size: fontSizeBase * 3,
font: pdfFont,
})
page.drawText(karakter.PancelVO.toString(), {
x: 512,
y: 515,
size: fontSizeBase * 2,
font: pdfFont,
})
page.drawText(karakter.PajzsVO.toString(), {
x: 512,
y: 482,
size: fontSizeBase * 2,
font: pdfFont,
})
const kozelharciTB = karakter.KozelharciTB.map(SignedNumberToText).join("/")
function getFontSize(length: number): number {
switch (length) {
case 1:
case 2:
return 24;
case 3:
return 18;
case 4:
return 14;
case 5:
return 11;
case 6:
return 9;
case 7:
return 8;
default:
return 6;
}
}
function getYOffset(length: number): number {
return Math.min(length - 2, 6);
}
const kozelHarciFontSize = getFontSize(kozelharciTB.length)
page.drawText(kozelharciTB, {
x: kozelharciTB.length > 4 ? 256 : 258,
y: 383 + getYOffset(kozelharciTB.length),
size: kozelHarciFontSize,
font: pdfFont,
})
const celzoTB = karakter.CelzoTB.map(SignedNumberToText).join("/")
const celzoFontSize = getFontSize(celzoTB.length)
page.drawText(celzoTB, {
x: celzoTB.length > 4 ? 343 : 346,
y: 383 + getYOffset(celzoTB.length),
size: celzoFontSize,
font: pdfFont,
})
drawFegyverek(karakter, pdfFont, fontSizeBase, page);
}
function fitTextInWidth(font: PDFFont, text: string, startingSize: number, maxWidth: number): number {
let size = startingSize
while(font.widthOfTextAtSize(text, size) > maxWidth) {
size--
}
return size
}
+72
View File
@@ -0,0 +1,72 @@
import {PDFFont, PDFPage, rgb} from "pdf-lib";
import {KarakterPdfView} from "./karakter_pdf_view";
import {SignedNumberToText} from "../components/Helpers";
import {Modifier} from "../domain-models/tulajdonsag";
export function DrawMentok(page: PDFPage, karakter: KarakterPdfView, fontSizeBase: number, pdfFont: PDFFont) {
const mentokAlap = karakter.MentokAlap
page.drawText(SignedNumberToText(mentokAlap.kitartas), {
x: 435,
y: 613,
size: fontSizeBase,
font: pdfFont,
color: rgb(0, 0, 0),
})
page.drawText(SignedNumberToText(mentokAlap.reflex), {
x: 435,
y: 580,
size: fontSizeBase,
font: pdfFont,
color: rgb(0, 0, 0),
})
page.drawText(SignedNumberToText(mentokAlap.akaratero), {
x: 435,
y: 547,
size: fontSizeBase,
font: pdfFont,
color: rgb(0, 0, 0),
})
page.drawText(SignedNumberToText(Modifier(karakter.Tulajdonsagok.t_egs)), {
x: 475,
y: 613,
size: fontSizeBase,
font: pdfFont,
color: rgb(0, 0, 0),
})
page.drawText(SignedNumberToText(Modifier(karakter.Tulajdonsagok.t_ugy)), {
x: 475,
y: 580,
size: fontSizeBase,
font: pdfFont,
color: rgb(0, 0, 0),
})
page.drawText(SignedNumberToText(Modifier(karakter.Tulajdonsagok.t_bol)), {
x: 475,
y: 547,
size: fontSizeBase,
font: pdfFont,
color: rgb(0, 0, 0),
})
const mentok = karakter.MentokModositokkal
page.drawText(SignedNumberToText(mentok.kitartas), {
x: 515,
y: 613,
size: fontSizeBase,
font: pdfFont,
color: rgb(0, 0, 0),
})
page.drawText(SignedNumberToText(mentok.reflex), {
x: 515,
y: 580,
size: fontSizeBase,
font: pdfFont,
color: rgb(0, 0, 0),
})
page.drawText(SignedNumberToText(mentok.akaratero), {
x: 515,
y: 547,
size: fontSizeBase,
font: pdfFont,
color: rgb(0, 0, 0),
})
}
+42
View File
@@ -0,0 +1,42 @@
import {PDFFont, PDFPage, rgb} from "pdf-lib";
import {KarakterPdfView} from "./karakter_pdf_view";
export function DrawOsztalySpecialsPage(page: PDFPage, font: PDFFont, karakter: KarakterPdfView){
const baseFontSize = 12
const titleFontSize = baseFontSize * 3
const pageCenterX = page.getWidth()/2
const titleWidth = font.widthOfTextAtSize(karakter.Osztaly, titleFontSize)
const titleX = pageCenterX - (titleWidth / 2)
page.drawText(karakter.Osztaly, {
x: titleX,
y: 770,
size: titleFontSize,
font: font,
color: rgb(0, 0, 0),
})
let rows = 0
// const margin = 30
// const textWidth = page.getWidth() - 2*margin;
for (let i = 0; i < karakter.OsztalySkills.length; i++) {
const skill = karakter.OsztalySkills[i];
page.drawText(skill.Name, {
x: 30,
y: 720 - rows,
size: baseFontSize,
font: font,
color: rgb(0, 0, 0),
})
page.drawText(skill.Description, {
x: 30,
y: 700 - rows,
size: baseFontSize,
font: font,
lineHeight: 16,
color: rgb(0, 0, 0),
// maxWidth: textWidth,
// wordBreaks: [' ', '-']
})
// rows += Math.ceil(font.widthOfTextAtSize(skill.Description, baseFontSize)/textWidth)*20 + 30
rows += skill.Description.split('\n').length*16 + 30
}
}
+90
View File
@@ -0,0 +1,90 @@
import {PDFFont, PDFPage, rgb} from "pdf-lib";
import {KarakterTulajdonsagok, Modifier} from "../domain-models/tulajdonsag";
import {SignedNumberToText} from "../components/Helpers";
export function DrawTulajdonsagok(page: PDFPage, tulajdonsagok: KarakterTulajdonsagok, fontSizeBase: number, pdfFont: PDFFont) {
page.drawText(tulajdonsagok.t_ero.toString(), {
x: 130,
y: 613,
size: fontSizeBase * 2,
font: pdfFont,
color: rgb(0, 0, 0),
})
page.drawText(SignedNumberToText(Modifier(tulajdonsagok.t_ero)), {
x: 176,
y: 613,
size: fontSizeBase * 2,
font: pdfFont,
color: rgb(0, 0, 0),
})
page.drawText(tulajdonsagok.t_ugy.toString(), {
x: 130,
y: 580,
size: fontSizeBase * 2,
font: pdfFont,
color: rgb(0, 0, 0),
})
page.drawText(SignedNumberToText(Modifier(tulajdonsagok.t_ugy)), {
x: 176,
y: 580,
size: fontSizeBase * 2,
font: pdfFont,
color: rgb(0, 0, 0),
})
page.drawText(tulajdonsagok.t_egs.toString(), {
x: 130,
y: 547,
size: fontSizeBase * 2,
font: pdfFont,
color: rgb(0, 0, 0),
})
page.drawText(SignedNumberToText(Modifier(tulajdonsagok.t_egs)), {
x: 176,
y: 547,
size: fontSizeBase * 2,
font: pdfFont,
color: rgb(0, 0, 0),
})
page.drawText(tulajdonsagok.t_int.toString(), {
x: 130,
y: 515,
size: fontSizeBase * 2,
font: pdfFont,
color: rgb(0, 0, 0),
})
page.drawText(SignedNumberToText(Modifier(tulajdonsagok.t_int)), {
x: 176,
y: 515,
size: fontSizeBase * 2,
font: pdfFont,
color: rgb(0, 0, 0),
})
page.drawText(tulajdonsagok.t_bol.toString(), {
x: 130,
y: 482,
size: fontSizeBase * 2,
font: pdfFont,
color: rgb(0, 0, 0),
})
page.drawText(SignedNumberToText(Modifier(tulajdonsagok.t_bol)), {
x: 176,
y: 482,
size: fontSizeBase * 2,
font: pdfFont,
color: rgb(0, 0, 0),
})
page.drawText(tulajdonsagok.t_kar.toString(), {
x: 130,
y: 449,
size: fontSizeBase * 2,
font: pdfFont,
color: rgb(0, 0, 0),
})
page.drawText(SignedNumberToText(Modifier(tulajdonsagok.t_kar)), {
x: 176,
y: 449,
size: fontSizeBase * 2,
font: pdfFont,
color: rgb(0, 0, 0),
})
}