Giter Club home page Giter Club logo

typr.ts's Introduction

Typr.ts

TypeScript class wrapper for photopea/Typr.js.

Design goal was to keep the core Typr.js fork in a separate branch as close to the original as possible to make eventual merging easier.

As of May 2020, the official photopea Typr.js project switched to using HarfBuzz and threw a lot of the font format parsing out. For that reason, my fork will have to continue it's own path.

I use this library in one of my own TypeScript projects and have only added class features that I needed.

  • Typr.parse(buffer) is done through the class constructor new typr.Font(buffer)
  • Typr.U functions are members of the class font.codeToGlyph(code)

Installation

npm install @fredli74/typr --save-dev

node load example

import * as fs from "fs";
import * as typr from '@fredli74/typr';

function toArrayBuffer(buf: Buffer) {
	let ab = new ArrayBuffer(buf.length);
	let view = new Uint8Array(ab);
	for (let i = 0; i < buf.length; ++i) {
		view[i] = buf[i];
	}
	return ab;
}
const data = fs.readFileSync("filename.ttf");
const font = new typr.Font(toArrayBuffer(data));

typr.ts's People

Contributors

fredli74 avatar lojjic avatar photopea avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

typr.ts's Issues

pathToSVG is broken

pathToSVG is broken, because the font instance is used as first parameter, but only the path is used in Typr.js.

return Typr_js_1.Typr.U.pathToSVG(this, path);

but in the source it is:

Typr.U.pathToSVG = function (path, prec) {}

So I guess it should be

return Typr_js_1.Typr.U.pathToSVG(path);

Same with pathToContext, otherwise thank you for the library.

Function getPairAdjustment returns double the amount of kerning offset

Hello,

I found a bug with the kerning of texts.

Typr.U.getPairAdjustment returns the double amount of kerning offset.

I already submitted an issue in the troika-three-text repository of lojjic because he uses your library.
protectwise/troika#196

Here is a screenshot of before and after I divide the value returned by getPairAdjustment by 2. The top one is wrong.
The 'T' and the 'e' should not be that close to each other.
The font I used is Calibri.

image

I found out, it could be this change which caused the bug: a9f3fe3

It seems like getPairAdjustment should only use either the 'GPOS' data or the 'kern' data and not both at the same time, because while debugging I saw, that they both return the same amount of kerning. So down below in if(font.kern) the offset is applied a second time.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.