Skip to content

Commit

Permalink
Merge branch 'fix-setting-subfamily' of https://github.com/StreakInTh…
Browse files Browse the repository at this point in the history
…eSky/opentype.js into fix-setting-subfamily
  • Loading branch information
StreakInTheSky committed Nov 8, 2023
2 parents bbbc067 + 2408dd2 commit 4b4b8bc
Show file tree
Hide file tree
Showing 16 changed files with 241 additions and 64 deletions.
11 changes: 11 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# To get started with Dependabot version updates, you'll need to specify which
# package ecosystems to update and where the package manifests are located.
# Please see the documentation for all configuration options:
# https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates

version: 2
updates:
- package-ecosystem: "npm" # See documentation for possible values
directory: "/" # Location of package manifests
schedule:
interval: "weekly"
63 changes: 49 additions & 14 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,25 +1,60 @@
name: release
name: Publish package to npm
run-name: npm - publish ${{ github.event.inputs.version }} to ${{ github.event.inputs.npmDistTag }}

on:
push:
tags:
- '*'
workflow_dispatch:
inputs:
version:
required: true
description: 'SemVer version for npm. (i.e. 1.0.0)'
npmDistTag:
required: true
default: 'latest'
dryRun:
description: 'Do a dry run (does not publish packages)'
type: boolean

jobs:
publish:
timeout-minutes: 25
runs-on: ubuntu-latest
permissions:
# required for publishing to npm with --provenance
# see https://docs.npmjs.com/generating-provenance-statements
id-token: write
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v2
- name: Print input
env:
THE_INPUT: '${{ toJson(github.event.inputs) }}'
run: |
echo $THE_INPUT
- uses: actions/checkout@v4

- uses: actions/setup-node@v3
with:
node-version: 18
node-version: 20
registry-url: 'https://registry.npmjs.org'
- run: npm install
- run: npm run build
- run: npm run dist
- run: npm run test
- run: npm pkg set name=$(basename ${{github.repository}})
- run: npm pkg set version=${{github.ref_name}}
- run: npm publish --access public

- name: Install dependencies
run: npm ci

- name: Build
run: npm run build

- name: Make dist files
run: npm run dist

- name: Run tests
run: npm run test

- name: Set version in package*.json
run: npm pkg set version=${{ github.event.inputs.version }}

- name: Publish package to npm
run: npm publish --access public --tag ${{ github.event.inputs.npmDistTag }} ${{ env.DRY_RUN }}
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
# https://docs.npmjs.com/generating-provenance-statements
NPM_CONFIG_PROVENANCE: true
DRY_RUN: ${{ github.event.inputs.dryRun == 'true' && '--dry-run' || '' }}
12 changes: 9 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
# opentype.js

JavaScript parser and writer for TrueType and OpenType fonts.
<div align="center">
<h1>opentype.js</h1>
<a href="https://www.npmjs.com/package/opentype.js"><img alt="Latest version on npm" src="https://img.shields.io/npm/v/opentype.js.svg?style=flat" /></a>
<a href="https://www.npmjs.com/package/opentype.js"><img alt="npm downloads, yearly" src="https://img.shields.io/npm/dy/opentype.js.svg?style=flat" /></a>
<a href="https://github.com/opentypejs/opentype.js/blob/master/LICENSE"><img alt="MIT License" src="https://img.shields.io/github/license/opentypejs/opentype.js" /></a>
<a href="https://github.com/opentypejs/opentype.js/actions/workflows/ci.yml?query=branch%3Amaster"><img alt="GitHub Workflow Status (with event)" src="https://img.shields.io/github/actions/workflow/status/opentypejs/opentype.js/ci.yml"></a>
<br /><br />
</div>

It gives you access to the **letterforms** of text from the browser or Node.js.

See [https://opentype.js.org/](https://opentype.js.org/) for a live demo.

## Features
Expand Down
70 changes: 35 additions & 35 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"devDependencies": {
"mocha": "^8.4.0",
"esbuild": "^0.19.5",
"eslint": "^8.52.0",
"eslint": "^8.53.0",
"reify": "^0.20.12"
},
"bin": {
Expand Down
2 changes: 1 addition & 1 deletion src/font.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ function Font(options) {
* @return {Boolean}
*/
Font.prototype.hasChar = function(c) {
return this.encoding.charToGlyphIndex(c) !== null;
return this.encoding.charToGlyphIndex(c) > 0;
};

/**
Expand Down
47 changes: 46 additions & 1 deletion src/tables/cff.js
Original file line number Diff line number Diff line change
Expand Up @@ -824,7 +824,52 @@ function parseCFFCharstring(font, glyph, code, version) {
break;
}

if (stack.length > 0 && !haveWidth) {
if (stack.length >= 4) {
// Type 2 Charstring Format Appendix C
// treat like Type 1 seac command (standard encoding accented character)
const acharName = cffStandardEncoding[stack.pop()];
const bcharName = cffStandardEncoding[stack.pop()];
const ady = stack.pop();
const adx = stack.pop();
// const asb = stack.pop(); // ignored for Type 2
if ( acharName && bcharName ) {
glyph.isComposite = true;
glyph.components = [];

const acharGlyphIndex = font.cffEncoding.charset.indexOf(acharName);
const bcharGlyphIndex = font.cffEncoding.charset.indexOf(bcharName);

glyph.components.push({
glyphIndex: bcharGlyphIndex,
dx: 0,
dy: 0
});
glyph.components.push({
glyphIndex: acharGlyphIndex,
dx: adx,
dy: ady
});
p.extend(font.glyphs.get(bcharGlyphIndex).path);
const acharGlyph = font.glyphs.get(acharGlyphIndex);
const shiftedCommands = JSON.parse(JSON.stringify(acharGlyph.path.commands)); // make a deep clone
for (let i = 0; i < shiftedCommands.length; i += 1) {
const cmd = shiftedCommands[i];
if (cmd.type !== 'Z') {
cmd.x += adx;
cmd.y += ady;
}
if ( cmd.type === 'Q' || cmd.type === 'C' ) {
cmd.x1 += adx;
cmd.y1 += ady;
}
if ( cmd.type === 'C' ) {
cmd.x2 += adx;
cmd.y2 += ady;
}
}
p.extend(shiftedCommands);
}
} else if (stack.length > 0 && !haveWidth) {
width = stack.shift() + nominalWidthX;
haveWidth = true;
}
Expand Down
Loading

0 comments on commit 4b4b8bc

Please sign in to comment.