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

Improved support for multi-line text #123

Open
kdzwinel opened this issue Jun 29, 2018 · 5 comments
Open

Improved support for multi-line text #123

kdzwinel opened this issue Jun 29, 2018 · 5 comments
Assignees

Comments

@kdzwinel
Copy link
Collaborator

kdzwinel commented Jun 29, 2018

Currently this:
screen shot 2018-06-29 at 11 29 23
Will render like this:
screen shot 2018-06-29 at 11 29 29

😵

Broken html (test case for working on this):

<div style='width: 200px'><b>Test</b>(s) or <b>TEST</b> may refer to: <b>Test</b> (assessment), an assessment intended to measure the respondents' knowledge or other abilities List of <b>tests</b></div>
@kdzwinel kdzwinel changed the title Support for mixed text Support for multi-line mixed text Jun 29, 2018
@kdzwinel
Copy link
Collaborator Author

kdzwinel commented Jun 29, 2018

Turns out inside single text block there can be multiple styles. We should migrate to that
screen shot 2018-06-29 at 12 33 05
(top text shows current approach)
(bottom text shows new approach)

@kdzwinel kdzwinel changed the title Support for multi-line mixed text Improved support for multi-line text Jun 29, 2018
@KimDal-hyeong
Copy link
Member

I add this data in text layer of asketch.json,

"forAttributedString": [
  {
    "content": "Text",
    "textStyles": {
      "color": "rgb(0, 0, 0)",
      "fontSize": 16,
      "fontFamily": "Times New Roman",
      "fontWeight": 400,
      "textDecoration": "none",
      "textAlign": "right",
      "textTransform": "none"
    }
  },
  {
    "content": " Styles",
    "textStyles": {
      "color": "rgb(255, 0, 0)",
      "fontSize": 20,
      "fontFamily": "Times New Roman",
      "fontWeight": 700,
      "textDecoration": "none",
      "textAlign": "right",
      "textTransform": "none"
    }
  }
]

and, change fixTextLayer in fixFont.js to this code.

export function fixTextLayer(layer) {
  layer.attributedString = makeEncodedAttributedString(layer.forAttributedString);
  delete layer.style;
  delete layer.text;
}

Its result is this.
2018-06-30 12 49 22

@kdzwinel
Copy link
Collaborator Author

@KimDal-hyeong oh wow, that's super useful! Thank you 🙇‍♂️

@kdzwinel kdzwinel added this to the 4.0.0 milestone Jul 3, 2018
@kdzwinel kdzwinel self-assigned this Jul 12, 2018
@kdzwinel
Copy link
Collaborator Author

It looks like we are using "text" objects with "style" property describing the "text style". However, that style is only a baseline style. "text" objects have "attributedString"s that consist of:

  • string e.g. "example text"
  • and multiple "attributes" that describe range (e.g. "location": 0, "length": 7) and font/color/size/etc (similar to "text style").

This way one "text" object can describe a string that uses various styles. We should use that instead of creating multiple "text" objects that get hard to arrange.

Example (with irrelevant stuff removed):

        {
            "_class": "text",
            "style": {
                "_class": "style",
                "textStyle": {
                    "_class": "textStyle",
                    "encodedAttributes": {
                        "MSAttributedStringFontAttribute": {
                            "_class": "fontDescriptor",
                            "attributes": {
                                "name": "TimesNewRomanPS-BoldMT",
                                "size": 10
                            }
                        },
                        "MSAttributedStringColorAttribute": {
                            "_class": "color",
                            "alpha": 1,
                            "blue": 0.2862745098039216,
                            "green": 0.2862745098039216,
                            "red": 0.2862745098039216
                        },
                    },
                },
            },
            "attributedString": {
                "_class": "attributedString",
                "string": "first second",
                "attributes": [
                    {
                        "_class": "stringAttribute",
                        "location": 0,
                        "length": 6,
                        "attributes": {
                            "MSAttributedStringFontAttribute": {
                                "_class": "fontDescriptor",
                                "attributes": {
                                    "name": "TimesNewRomanPS-BoldMT",
                                    "size": 10
                                }
                            },
                            "MSAttributedStringColorAttribute": {
                                "_class": "color",
                                "alpha": 1,
                                "blue": 0.2862745098039216,
                                "green": 0.2862745098039216,
                                "red": 0.2862745098039216
                            },
                            "textStyleVerticalAlignmentKey": 0,
                            "paragraphStyle": {
                                "_class": "paragraphStyle",
                                "alignment": 0,
                                "lineHeightMultiple": 1
                            }
                        }
                    },
                    {
                        "_class": "stringAttribute",
                        "location": 6,
                        "length": 6,
                        "attributes": {

@kdzwinel kdzwinel modified the milestones: 4.0.0, 4.1.0 Jul 26, 2018
@nataliyakarat
Copy link

Hi! Any plans to fix that?

Looks pretty bad
screenshot 2019-01-24 at 17 32 10

@kdzwinel kdzwinel removed this from the 4.1.0 milestone Aug 23, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants