Skip to content

Commit

Permalink
fix getting the font name
Browse files Browse the repository at this point in the history
  • Loading branch information
mathieudutour committed May 7, 2020
1 parent 5882101 commit eb27407
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 6 deletions.
4 changes: 2 additions & 2 deletions __tests__/jest/sharedStyles/TextStyles.ts
Expand Up @@ -132,7 +132,7 @@ describe('create', () => {
const input = [...whitelist, ...blacklist].reduce(
(acc, key) => ({
...acc,
[key]: true,
[key]: '',
}),
{},
);
Expand All @@ -142,7 +142,7 @@ describe('create', () => {
const firstStoredStyle = res[Object.keys(res)[0]].cssStyle;

whitelist.forEach((key) => {
expect(firstStoredStyle).toHaveProperty(key, true);
expect(firstStoredStyle).toHaveProperty(key, '');
});

blacklist.forEach((key) => {
Expand Down
7 changes: 5 additions & 2 deletions examples/basic-setup/src/my-command.js
@@ -1,6 +1,6 @@
import * as React from 'react';
import * as PropTypes from 'prop-types';
import { render, Artboard, Text, View } from 'react-sketchapp';
import { render, Artboard, Text, View } from '../../../lib';
import chroma from 'chroma-js';

// take a hex and give us a nice text color to put over it
Expand All @@ -23,7 +23,10 @@ const Swatch = ({ name, hex }) => (
padding: 8,
}}
>
<Text name="Swatch Name" style={{ color: textColor(hex), fontWeight: 'bold' }}>
<Text
name="Swatch Name"
style={{ color: textColor(hex), fontWeight: 'bold', fontFamily: 'Helvetica' }}
>
{name}
</Text>
<Text name="Swatch Hex" style={{ color: textColor(hex) }}>
Expand Down
2 changes: 1 addition & 1 deletion src/jsonUtils/textLayers.ts
Expand Up @@ -57,7 +57,7 @@ const makeFontDescriptor = (bridge: PlatformBridge) => (
): FileFormat.FontDescriptor => ({
_class: 'fontDescriptor',
attributes: {
name: bridge.findFontName(String(style)), // will default to the system font
name: bridge.findFontName(style), // will default to the system font
size: style.fontSize || 14,
},
});
Expand Down
2 changes: 1 addition & 1 deletion src/platformBridges/sketch/findFontName.ts
Expand Up @@ -192,5 +192,5 @@ export const findFont = (style: TextStyle): NSFont => {

export function findFontName(style: TextStyle): string {
const font = findFont(style);
return font.fontDescriptor().postscriptName();
return String(font.fontDescriptor().postscriptName());
}

0 comments on commit eb27407

Please sign in to comment.