Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Text.Style.fontAxes issue #810

Open
qjebbs opened this issue Nov 2, 2020 · 2 comments
Open

Text.Style.fontAxes issue #810

qjebbs opened this issue Nov 2, 2020 · 2 comments

Comments

@qjebbs
Copy link

qjebbs commented Nov 2, 2020

error.zip

Above is a file reported by one my user, many of them encountered issues in this part.

How to reproduce

  1. Sketch prompts font is missing
  2. Replace the font with Work Sans-Medium

then, try:

    console.log(layer.style.fontAxes)
    console.log(JSON.stringify(layer.style.fontAxes))
    console.log(typeof (layer.style.fontAxes as any).Weight.value)

Output:

  { Weight: { id: 2003265652, min: 100, max: 900, value: 500 } }
  '{"Weight":{"id":{},"min":{},"max":{},"value":{}}}'
  'object'

Issues

  1. If I assign above layer.style to another layer, Sketch crashes instantly
  2. Text.Style.fontAxes doesn't have property Weight according to documentation
  3. All values provided by Sketch API should be JS type. But Weight.value is object (Obj-C?). So JSON.stringify doesn't work with it

No matter what has happened, I think the API should do the compatible magic to these circumstances.

@qjebbs
Copy link
Author

qjebbs commented Nov 2, 2020

PS

The screenshot of evaluate Object.keys() on null, happens on Text.Style.fontAxes=null(Obj-C type of null?), on uncertain conditions, I haven't find a way to reproduce.

I use following codes to bypass:

// prepare to copy from style source
let styleStr = JSON.stringify(layer.style);
let styleBase = JSON.parse(styleStr);
if (styleBase.fontAxes) {
    // fontAxes issue: https://github.com/sketch-hq/SketchAPI/issues/810
    styleBase.fontAxes = Object.assign({}, <FontAxes>{
        id: styleBase.fontAxes.id,
        min: styleBase.fontAxes.min,
        max: styleBase.fontAxes.max,
        value: styleBase.fontAxes.value
    })
} else {
    // bypass Sketch API evaluating Object.keys() on null fontAxes
    delete styleBase.fontAxes;
}
styleStr = JSON.stringify(styleBase);

// ...

newLayer.style = JSON.parse(styleStr)

@qjebbs
Copy link
Author

qjebbs commented Nov 4, 2020

This file shows more issue about fontAxes: error2.zip

run:

let layer = context.document.pages[0].layers[0].layers[0] as Text;
console.log(layer.style.fontAxes);

output:

  fontAxes: 
     { 'Optical Size': { id: 1869640570, min: 19.8999, max: 20, value: 19.8999 },
       GRAD: { id: 1196572996, min: 400, max: 1000, value: 400 },
       YAXS: { id: 1497454675, min: 400, max: 1000, value: 400 },
       Weight: { id: 2003265652, min: 1, max: 1000, value: 400 } } }

If I assign this style to another layer, Sketch crashes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant