commit b983a524124345f1751c01a156dbe1c398350bae Author: morbalint Date: Sun Feb 11 22:27:11 2024 +0100 initial diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..05d0fe4 --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +node_modules/ +dist/ +fonts/ +!fonts/Milonga-Regular.ttf \ No newline at end of file diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..b58b603 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,5 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ diff --git a/.idea/kem2karakterlap.iml b/.idea/kem2karakterlap.iml new file mode 100644 index 0000000..24643cc --- /dev/null +++ b/.idea/kem2karakterlap.iml @@ -0,0 +1,12 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..a5bdcea --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.tool-versions b/.tool-versions new file mode 100644 index 0000000..a851188 --- /dev/null +++ b/.tool-versions @@ -0,0 +1 @@ +nodejs 20.4.0 diff --git a/index.ts b/index.ts new file mode 100644 index 0000000..7a268bd --- /dev/null +++ b/index.ts @@ -0,0 +1,7 @@ +import {Karlap} from "./karlap"; + +Karlap().then(() => { + console.log("Done") +}).catch(reason => { + console.error(reason) +}) diff --git a/karlap.pdf b/karlap.pdf new file mode 100644 index 0000000..b66e75f Binary files /dev/null and b/karlap.pdf differ diff --git a/karlap.ts b/karlap.ts new file mode 100644 index 0000000..cc6fbee --- /dev/null +++ b/karlap.ts @@ -0,0 +1,267 @@ +import {PageSizes, PDFDocument, PDFFont, PDFPage, rgb} from "pdf-lib"; +import fs from "fs/promises"; +import fontKit from "@pdf-lib/fontkit" + + +export async function Karlap() { + const docBuffer = await fs.readFile("kem2karakterlap_minden.pdf", {encoding: null, flag: 'r'}) + const doc = await PDFDocument.load(docBuffer) + doc.registerFontkit(fontKit) + const fontBuffer = await fs.readFile("fonts/Milonga-Regular.ttf", {encoding: null, flag: 'r'}) + const pdfFont = await doc.embedFont(fontBuffer) + const form = doc.getForm() + + const page0 = doc.getPage(0) + + const addTextFieldToPage = (page: PDFPage) => (options: {name: string, x: number, y: number, w: number, h: number}) => { + const field = form.createTextField(options.name) + field.addToPage(page0, { + x: options.x, + y: options.y, + font: pdfFont, + borderColor: rgb(1,1,1), + width: options.w, + height: options.h, + }) + } + + const addTextField0 = addTextFieldToPage(page0) + + addTextField0({ + name: "nev_faj_osztaly", + x: 55, + y: 730, + w: 420, + h: 24 + }) + addTextField0({ + name: "szint", + x: 495, + y: 711, + w: 36, + h: 36 + }) + + addTextField0({ + name: "vo", + x: 210, + y: 690, + w: 28, + h: 28 + }) + addTextField0({ + name: "pancel", + x: 303, + y: 705, + w: 24, + h: 16 + }) + addTextField0({ + name: "pajzs", + x: 369, + y: 705, + w: 24, + h: 16 + }) + addTextField0({ + name: "egyeb_vo", + x: 436, + y: 705, + w: 24, + h: 16 + }) + + // Tulajdonsagok + addTextField0({ + name: "tul_ero", + x: 130, + y: 688, + w: 24, + h: 16 + }) + addTextField0({ + name: "tul_ero_mod", + x: 169, + y: 688, + w: 14, + h: 16 + }) + addTextField0({ + name: "tul_ugy", + x: 130, + y: 660, + w: 24, + h: 16 + }) + addTextField0({ + name: "tul_ugy_mod", + x: 169, + y: 660, + w: 14, + h: 16 + }) + addTextField0({ + name: "tul_egs", + x: 130, + y: 631, + w: 24, + h: 16 + }) + addTextField0({ + name: "tul_egs_mod", + x: 169, + y: 631, + w: 14, + h: 16 + }) + addTextField0({ + name: "tul_int", + x: 130, + y: 603, + w: 24, + h: 16 + }) + addTextField0({ + name: "tul_int_mod", + x: 169, + y: 603, + w: 14, + h: 16 + }) + addTextField0({ + name: "tul_bol", + x: 130, + y: 575, + w: 24, + h: 16 + }) + addTextField0({ + name: "tul_bol_mod", + x: 169, + y: 575, + w: 14, + h: 16 + }) + addTextField0({ + name: "tul_kar", + x: 130, + y: 546, + w: 24, + h: 16 + }) + addTextField0({ + name: "tul_kar_mod", + x: 169, + y: 546, + w: 14, + h: 16 + }) + + addTextField0({ + name: "jellem", + x: 385, + y: 680, + w: 113, + h: 16 + }) + addTextField0({ + name: "istenseg", + x: 385, + y: 651, + w: 150, + h: 16 + }) + + // HP + addTextField0({ + name: "hp_rolls", + x: 199, + y: 640, + w: 175, + h: 16 + }) + addTextField0({ + name: "hp_aktualis", + x: 203, + y: 600, + w: 170, + h: 16 + }) + + // Mentők + addTextField0({ + name: "kitartas_alap", + x: 445, + y: 617, + w: 24, + h: 16 + }) + addTextField0({ + name: "kitartas_mod", + x: 479, + y: 617, + w: 24, + h: 16 + }) + addTextField0({ + name: "kitartas_sum", + x: 518, + y: 618, + w: 14, + h: 14 + }) + addTextField0({ + name: "reflex_alap", + x: 445, + y: 589, + w: 24, + h: 16 + }) + addTextField0({ + name: "reflex_mod", + x: 479, + y: 589, + w: 24, + h: 16 + }) + addTextField0({ + name: "reflex_sum", + x: 518, + y: 590, + w: 14, + h: 14 + }) + addTextField0({ + name: "akaratero_alap", + x: 445, + y: 560, + w: 24, + h: 16 + }) + addTextField0({ + name: "akaratero_mod", + x: 479, + y: 560, + w: 24, + h: 16 + }) + addTextField0({ + name: "akaratero_sum", + x: 518, + y: 561, + w: 14, + h: 14 + }) + + addTextField0({ + name: "kezdemenyezes", + x: 518, + y: 536, + w: 14, + h: 14 + }) + + const pdfBytes = await doc.save() + + await fs.writeFile("karlap.pdf", pdfBytes) +} \ No newline at end of file diff --git a/kem2karakterlap_minden.pdf b/kem2karakterlap_minden.pdf new file mode 100644 index 0000000..85bfd9b Binary files /dev/null and b/kem2karakterlap_minden.pdf differ diff --git a/package.json b/package.json new file mode 100644 index 0000000..5dc183c --- /dev/null +++ b/package.json @@ -0,0 +1,15 @@ +{ + "name": "kem2karakterlap", + "version": "1.0.0", + "main": "index.js", + "license": "MIT", + "private": true, + "devDependencies": { + "@types/node": "^20.11.9", + "typescript": "^5.3.3" + }, + "dependencies": { + "@pdf-lib/fontkit": "^1.1.1", + "pdf-lib": "^1.17.1" + } +} diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 0000000..796bd83 --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,109 @@ +{ + "compilerOptions": { + /* Visit https://aka.ms/tsconfig to read more about this file */ + + /* Projects */ + // "incremental": true, /* Save .tsbuildinfo files to allow for incremental compilation of projects. */ + // "composite": true, /* Enable constraints that allow a TypeScript project to be used with project references. */ + // "tsBuildInfoFile": "./.tsbuildinfo", /* Specify the path to .tsbuildinfo incremental compilation file. */ + // "disableSourceOfProjectReferenceRedirect": true, /* Disable preferring source files instead of declaration files when referencing composite projects. */ + // "disableSolutionSearching": true, /* Opt a project out of multi-project reference checking when editing. */ + // "disableReferencedProjectLoad": true, /* Reduce the number of projects loaded automatically by TypeScript. */ + + /* Language and Environment */ + "target": "es2016", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */ + // "lib": [], /* Specify a set of bundled library declaration files that describe the target runtime environment. */ + // "jsx": "preserve", /* Specify what JSX code is generated. */ + // "experimentalDecorators": true, /* Enable experimental support for legacy experimental decorators. */ + // "emitDecoratorMetadata": true, /* Emit design-type metadata for decorated declarations in source files. */ + // "jsxFactory": "", /* Specify the JSX factory function used when targeting React JSX emit, e.g. 'React.createElement' or 'h'. */ + // "jsxFragmentFactory": "", /* Specify the JSX Fragment reference used for fragments when targeting React JSX emit e.g. 'React.Fragment' or 'Fragment'. */ + // "jsxImportSource": "", /* Specify module specifier used to import the JSX factory functions when using 'jsx: react-jsx*'. */ + // "reactNamespace": "", /* Specify the object invoked for 'createElement'. This only applies when targeting 'react' JSX emit. */ + // "noLib": true, /* Disable including any library files, including the default lib.d.ts. */ + // "useDefineForClassFields": true, /* Emit ECMAScript-standard-compliant class fields. */ + // "moduleDetection": "auto", /* Control what method is used to detect module-format JS files. */ + + /* Modules */ + "module": "CommonJS", /* Specify what module code is generated. */ + // "rootDir": "./", /* Specify the root folder within your source files. */ + // "moduleResolution": "node10", /* Specify how TypeScript looks up a file from a given module specifier. */ + // "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */ + // "paths": {}, /* Specify a set of entries that re-map imports to additional lookup locations. */ + // "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */ + // "typeRoots": [], /* Specify multiple folders that act like './node_modules/@types'. */ + // "types": [], /* Specify type package names to be included without being referenced in a source file. */ + // "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */ + // "moduleSuffixes": [], /* List of file name suffixes to search when resolving a module. */ + // "allowImportingTsExtensions": true, /* Allow imports to include TypeScript file extensions. Requires '--moduleResolution bundler' and either '--noEmit' or '--emitDeclarationOnly' to be set. */ + // "resolvePackageJsonExports": true, /* Use the package.json 'exports' field when resolving package imports. */ + // "resolvePackageJsonImports": true, /* Use the package.json 'imports' field when resolving imports. */ + // "customConditions": [], /* Conditions to set in addition to the resolver-specific defaults when resolving imports. */ + // "resolveJsonModule": true, /* Enable importing .json files. */ + // "allowArbitraryExtensions": true, /* Enable importing files with any extension, provided a declaration file is present. */ + // "noResolve": true, /* Disallow 'import's, 'require's or ''s from expanding the number of files TypeScript should add to a project. */ + + /* JavaScript Support */ + // "allowJs": true, /* Allow JavaScript files to be a part of your program. Use the 'checkJS' option to get errors from these files. */ + // "checkJs": true, /* Enable error reporting in type-checked JavaScript files. */ + // "maxNodeModuleJsDepth": 1, /* Specify the maximum folder depth used for checking JavaScript files from 'node_modules'. Only applicable with 'allowJs'. */ + + /* Emit */ + // "declaration": true, /* Generate .d.ts files from TypeScript and JavaScript files in your project. */ + // "declarationMap": true, /* Create sourcemaps for d.ts files. */ + // "emitDeclarationOnly": true, /* Only output d.ts files and not JavaScript files. */ + // "sourceMap": true, /* Create source map files for emitted JavaScript files. */ + // "inlineSourceMap": true, /* Include sourcemap files inside the emitted JavaScript. */ + // "outFile": "./", /* Specify a file that bundles all outputs into one JavaScript file. If 'declaration' is true, also designates a file that bundles all .d.ts output. */ + "outDir": "./dist/", /* Specify an output folder for all emitted files. */ + // "removeComments": true, /* Disable emitting comments. */ + // "noEmit": true, /* Disable emitting files from a compilation. */ + // "importHelpers": true, /* Allow importing helper functions from tslib once per project, instead of including them per-file. */ + // "importsNotUsedAsValues": "remove", /* Specify emit/checking behavior for imports that are only used for types. */ + // "downlevelIteration": true, /* Emit more compliant, but verbose and less performant JavaScript for iteration. */ + // "sourceRoot": "", /* Specify the root path for debuggers to find the reference source code. */ + // "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */ + // "inlineSources": true, /* Include source code in the sourcemaps inside the emitted JavaScript. */ + // "emitBOM": true, /* Emit a UTF-8 Byte Order Mark (BOM) in the beginning of output files. */ + // "newLine": "crlf", /* Set the newline character for emitting files. */ + // "stripInternal": true, /* Disable emitting declarations that have '@internal' in their JSDoc comments. */ + // "noEmitHelpers": true, /* Disable generating custom helper functions like '__extends' in compiled output. */ + // "noEmitOnError": true, /* Disable emitting files if any type checking errors are reported. */ + // "preserveConstEnums": true, /* Disable erasing 'const enum' declarations in generated code. */ + // "declarationDir": "./", /* Specify the output directory for generated declaration files. */ + // "preserveValueImports": true, /* Preserve unused imported values in the JavaScript output that would otherwise be removed. */ + + /* Interop Constraints */ + // "isolatedModules": true, /* Ensure that each file can be safely transpiled without relying on other imports. */ + // "verbatimModuleSyntax": true, /* Do not transform or elide any imports or exports not marked as type-only, ensuring they are written in the output file's format based on the 'module' setting. */ + // "allowSyntheticDefaultImports": true, /* Allow 'import x from y' when a module doesn't have a default export. */ + "esModuleInterop": true, /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */ + // "preserveSymlinks": true, /* Disable resolving symlinks to their realpath. This correlates to the same flag in node. */ + "forceConsistentCasingInFileNames": true, /* Ensure that casing is correct in imports. */ + + /* Type Checking */ + "strict": true, /* Enable all strict type-checking options. */ + // "noImplicitAny": true, /* Enable error reporting for expressions and declarations with an implied 'any' type. */ + // "strictNullChecks": true, /* When type checking, take into account 'null' and 'undefined'. */ + // "strictFunctionTypes": true, /* When assigning functions, check to ensure parameters and the return values are subtype-compatible. */ + // "strictBindCallApply": true, /* Check that the arguments for 'bind', 'call', and 'apply' methods match the original function. */ + // "strictPropertyInitialization": true, /* Check for class properties that are declared but not set in the constructor. */ + // "noImplicitThis": true, /* Enable error reporting when 'this' is given the type 'any'. */ + // "useUnknownInCatchVariables": true, /* Default catch clause variables as 'unknown' instead of 'any'. */ + // "alwaysStrict": true, /* Ensure 'use strict' is always emitted. */ + // "noUnusedLocals": true, /* Enable error reporting when local variables aren't read. */ + // "noUnusedParameters": true, /* Raise an error when a function parameter isn't read. */ + // "exactOptionalPropertyTypes": true, /* Interpret optional property types as written, rather than adding 'undefined'. */ + // "noImplicitReturns": true, /* Enable error reporting for codepaths that do not explicitly return in a function. */ + // "noFallthroughCasesInSwitch": true, /* Enable error reporting for fallthrough cases in switch statements. */ + // "noUncheckedIndexedAccess": true, /* Add 'undefined' to a type when accessed using an index. */ + // "noImplicitOverride": true, /* Ensure overriding members in derived classes are marked with an override modifier. */ + // "noPropertyAccessFromIndexSignature": true, /* Enforces using indexed accessors for keys declared using an indexed type. */ + // "allowUnusedLabels": true, /* Disable error reporting for unused labels. */ + // "allowUnreachableCode": true, /* Disable error reporting for unreachable code. */ + + /* Completeness */ + // "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */ + "skipLibCheck": true /* Skip type checking all .d.ts files. */ + } +} diff --git a/yarn.lock b/yarn.lock new file mode 100644 index 0000000..d693fad --- /dev/null +++ b/yarn.lock @@ -0,0 +1,61 @@ +# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. +# yarn lockfile v1 + + +"@pdf-lib/fontkit@^1.1.1": + version "1.1.1" + resolved "https://registry.yarnpkg.com/@pdf-lib/fontkit/-/fontkit-1.1.1.tgz#f18473892b65e3253eb73f4569785abd2c03b1e0" + integrity sha512-KjMd7grNapIWS/Dm0gvfHEilSyAmeLvrEGVcqLGi0VYebuqqzTbgF29efCx7tvx+IEbG3zQciRSWl3GkUSvjZg== + dependencies: + pako "^1.0.6" + +"@pdf-lib/standard-fonts@^1.0.0": + version "1.0.0" + resolved "https://registry.yarnpkg.com/@pdf-lib/standard-fonts/-/standard-fonts-1.0.0.tgz#8ba691c4421f71662ed07c9a0294b44528af2d7f" + integrity sha512-hU30BK9IUN/su0Mn9VdlVKsWBS6GyhVfqjwl1FjZN4TxP6cCw0jP2w7V3Hf5uX7M0AZJ16vey9yE0ny7Sa59ZA== + dependencies: + pako "^1.0.6" + +"@pdf-lib/upng@^1.0.1": + version "1.0.1" + resolved "https://registry.yarnpkg.com/@pdf-lib/upng/-/upng-1.0.1.tgz#7dc9c636271aca007a9df4deaf2dd7e7960280cb" + integrity sha512-dQK2FUMQtowVP00mtIksrlZhdFXQZPC+taih1q4CvPZ5vqdxR/LKBaFg0oAfzd1GlHZXXSPdQfzQnt+ViGvEIQ== + dependencies: + pako "^1.0.10" + +"@types/node@^20.11.9": + version "20.11.9" + resolved "https://registry.yarnpkg.com/@types/node/-/node-20.11.9.tgz#959d436f20ce2ee3df897c3eaa0617c98fa70efb" + integrity sha512-CQXNuMoS/VcoAMISe5pm4JnEd1Br5jildbQEToEMQvutmv+EaQr90ry9raiudgpyDuqFiV9e4rnjSfLNq12M5w== + dependencies: + undici-types "~5.26.4" + +pako@^1.0.10, pako@^1.0.11, pako@^1.0.6: + version "1.0.11" + resolved "https://registry.yarnpkg.com/pako/-/pako-1.0.11.tgz#6c9599d340d54dfd3946380252a35705a6b992bf" + integrity sha512-4hLB8Py4zZce5s4yd9XzopqwVv/yGNhV1Bl8NTmCq1763HeK2+EwVTv+leGeL13Dnh2wfbqowVPXCIO0z4taYw== + +pdf-lib@^1.17.1: + version "1.17.1" + resolved "https://registry.yarnpkg.com/pdf-lib/-/pdf-lib-1.17.1.tgz#9e7dd21261a0c1fb17992580885b39e7d08f451f" + integrity sha512-V/mpyJAoTsN4cnP31vc0wfNA1+p20evqqnap0KLoRUN0Yk/p3wN52DOEsL4oBFcLdb76hlpKPtzJIgo67j/XLw== + dependencies: + "@pdf-lib/standard-fonts" "^1.0.0" + "@pdf-lib/upng" "^1.0.1" + pako "^1.0.11" + tslib "^1.11.1" + +tslib@^1.11.1: + version "1.14.1" + resolved "https://registry.yarnpkg.com/tslib/-/tslib-1.14.1.tgz#cf2d38bdc34a134bcaf1091c41f6619e2f672d00" + integrity sha512-Xni35NKzjgMrwevysHTCArtLDpPvye8zV/0E4EyYn43P7/7qvQwPh9BGkHewbMulVntbigmcT7rdX3BNo9wRJg== + +typescript@^5.3.3: + version "5.3.3" + resolved "https://registry.yarnpkg.com/typescript/-/typescript-5.3.3.tgz#b3ce6ba258e72e6305ba66f5c9b452aaee3ffe37" + integrity sha512-pXWcraxM0uxAS+tN0AG/BF2TyqmHO014Z070UsJ+pFvYuRSq8KH8DmWpnbXe0pEPDHXZV3FcAbJkijJ5oNEnWw== + +undici-types@~5.26.4: + version "5.26.5" + resolved "https://registry.yarnpkg.com/undici-types/-/undici-types-5.26.5.tgz#bcd539893d00b56e964fd2657a4866b221a65617" + integrity sha512-JlCMO+ehdEIKqlFxk6IfVoAUVmgz7cU7zD/h9XZ0qzeosSHmUJVOzSQvvYSYWXkFXC+IfLKSIffhv0sVZup6pA==