{"id":23500431,"url":"https://github.com/techninja/hersheytextjs","last_synced_at":"2025-04-15T18:42:26.642Z","repository":{"id":17688286,"uuid":"20494198","full_name":"techninja/hersheytextjs","owner":"techninja","description":"A port of the Hershey engraving fonts to JSON for JavaScript/SVG","archived":false,"fork":false,"pushed_at":"2023-04-15T20:12:15.000Z","size":333,"stargazers_count":55,"open_issues_count":8,"forks_count":6,"subscribers_count":1,"default_branch":"master","last_synced_at":"2024-08-08T15:47:01.858Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"http://techninja.github.io/hersheytextjs/","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/techninja.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-06-04T18:09:35.000Z","updated_at":"2024-08-04T20:25:31.000Z","dependencies_parsed_at":"2022-09-11T15:30:55.539Z","dependency_job_id":null,"html_url":"https://github.com/techninja/hersheytextjs","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/techninja%2Fhersheytextjs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/techninja%2Fhersheytextjs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/techninja%2Fhersheytextjs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/techninja%2Fhersheytextjs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/techninja","download_url":"https://codeload.github.com/techninja/hersheytextjs/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":231186899,"owners_count":18340890,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-12-25T06:44:16.168Z","updated_at":"2024-12-25T06:44:16.947Z","avatar_url":"https://github.com/techninja.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Hershey Text JS\n\nA port of the\n[EMSL Hershey engraving font](http://www.evilmadscientist.com/2011/hershey-text-an-inkscape-extension-for-engraving-fonts/)\ndata from the [Hershey Text Inkscape Plugin](https://code.google.com/p/eggbotcode/downloads/list?can=3\u0026q=hershey)\nto JSON, capable of being rendered quickly via JavaScript \u0026 SVG.\n\nThis includes an quickly written example renderer, see the demo on the\n[live github page](http://techninja.github.io/hersheytextjs/) to give it a try!\n\nJSON data only contains original Hershey font data, but Node.js module allows access to\nthis and all included SVG fonts and an API to add your own!\n\n## Clientside Use\n\nLoad the structured JSON data and use it to create your own renderer, or use the example\nas a starting point.\n\n## Node.js: Install \u0026 Include\n\nInstall via `npm install hersheytext`, then include in your node script with\n`const hershey = require('hersheytext');`.\n\n### JSON data source\n\nThe JSON font data will be accessible at `hershey.fonts`, EG:\n`hershey.fonts['futural'].chars[2]`. The `chars[n].d` string value can be put directly\ninto the `d` attribute within a `\u003cpath\u003e` SVG element, or imported to a\n[Paper.js compound path](http://paperjs.org/reference/compoundpath).\n\nSee hersheytest.js for more data usage examples, check `lib/hersheytext.js` for full\nfunction level documentation.\n\n### Get raw font data\n\nYou can access either SVG or Hershey font raw data using `getFontData()`:\n\n```javascript\nconst hershey = require('hersheytext');\n\nconsole.log('All fonts available', hershey.getFonts());\n\nconst svgFont = hershey.getFontData('ems_tech');\nconsole.log('Font Type:', svgFont.type);\nconsole.log('SVG \u003cfont-face\u003e cap height:', svgFont.info['cap-height']);\nconsole.log('SVG \u003cfont\u003e default char kern width:', svgFont.info['horiz-adv-x']);\nconsole.log('SVG \u003cglyph\u003e exclamation char data:', svgFont.getChar('!'));\n\nconst hersheyFont = hershey.getFontData('cursive');\nconsole.log('Font Type:', hersheyFont.type);\nconsole.log('Hershey Font Display Name:', hersheyFont.info['font-family']);\nconsole.log(`Hershey Font 'A' kern width:`, hersheyFont.getChar('A').width);\nconsole.log('Hershey Font exclamation char data:', hersheyFont.getChar('!').d);\n```\n\n### Render to SVG directly\n\nHershey Text JS comes with a very simple single line renderer, `renderTextSVG()`, which\nreturns a formatted group of characters with correct offsets.\n\n```javascript\nconst hershey = require('hersheytext');\nconst fs = require('fs');\n\nconst options = {\n  font: 'hershey_script_1',\n  scale: 0.25,\n};\n\nconst header = '\u003csvg xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" version=\"1.1\"\u003e';\nconst data = hershey.renderTextSVG('Take a Look, if you Will.', options);\nconst footer = '\u003c/svg\u003e';\n\nfs.writeFileSync('test.svg', `${header}\\n${data}\\n${footer}`);\n```\n\n### Make your own renderer with text array\n\nIf you have your own rendering intent that isn't SVG directly, the render array function\nis the easiest way to do that. To render plain text into an array of easily renderable\ncharacter data from SVG or Hershey font data, start with something like this:\n\n```javascript\nconst hershey = require('hersheytext');\nconst textArray = hershey.renderTextArray('Hello World!', { font: 'ems_allure' });\n\ntextArray.forEach(char =\u003e {\n  console.log('--------------------------------------------');\n  console.log('Character:', char.type);\n  console.log('Name:', char.name);\n  console.log('Kerning Width (in font units):', char.width);\n  console.log('Path Data:', char.d);\n});\n```\n\n### Add a custom SVG font\n\nIf you have an SVG font you'd like to use that isn't one of the ones HersheyText JS ships\nwith, just use `addSVGFont()`:\n\n```javascript\nconst hershey = require('hersheytext');\n\n// Will return false if there was a problem. See console for errors.\nhershey.addSVGFont('path/to/my-test-font.svg');\n\n// Machine name will be SVG font-family, lowercase with spaces replaced with underscores.\nconst options = { font: 'my_test_font' };\nconst data = hershey.renderTextSVG('In my own custom font!', options);\n```\n\n**Notes:**\n\n* Raw SVG font data is in glyph format, and therefore needs to be Y-inverted after\nit's been positioned, EG: `\u003cpath transform=\"scale(1, -1)\" …`\n* Hershey font data is in its own far smaller scale and does not need to be inverted.\n\n--------\nJSON data Public Domain, All other code MIT Licensed.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftechninja%2Fhersheytextjs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftechninja%2Fhersheytextjs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftechninja%2Fhersheytextjs/lists"}