Giter VIP home page Giter VIP logo

Comments (3)

mascardoso avatar mascardoso commented on August 11, 2024 1

@ysjn this definitely helps to get me through a direction.
Thank you so much with the thorough explanation.
I will let you know about my findings soon.
Thank you

from bold-it.

ysjn avatar ysjn commented on August 11, 2024

Hi @mascardoso, sorry for my late reply.

Please note that I'm new to cocoa-script and Objective-c, Sketch plugin authoring 😉

I did some quick search and came to conclusion that maybe you can use attributedStringValue() from Objective-c.

import sketch from 'sketch'

export default function() {
  const selection = context.selection;

  for (var index = selection.length - 1; index >= 0; index--) {
    var layer = selection[index];
    console.log(layer.attributedStringValue().string);
  }
}

From the code above, you can retrieve an object that contains all paragraph styles from text layer(s).
If I run that code against text layer that contains something like,

"Type something"

I would get:

<MOMethod: 0x600000c25860 : target=0x608001227c00
Type {
    MSAttributedStringColorAttribute = "<MSImmutableColor: 0x600000c66800> (C10CE689-E370-4BBC-9EE8-B4BE54858E53)";
    NSFont = "\"ArialMT 13.00 pt. P [] (0x600001258d80) fobj=0x7fbb1973f100, spc=3.61\"";
    NSParagraphStyle = "Alignment 0, LineSpacing 0, ParagraphSpacing 0, ParagraphSpacingBefore 0, HeadIndent 0, TailIndent 0, FirstLineHeadIndent 0, LineHeight 0/0, LineHeightMultiple 0, LineBreakMode 0, Tabs (\n    28L,\n    56L,\n    84L,\n    112L,\n    140L,\n    168L,\n    196L,\n    224L,\n    252L,\n    280L,\n    308L,\n    336L\n), DefaultTabInterval 0, Blocks (\n), Lists (\n), BaseWritingDirection -1, HyphenationFactor 0, TighteningForTruncation NO, HeaderLevel 0";
    textStyleVerticalAlignmentKey = 0;
}
something{
    MSAttributedStringColorAttribute = "<MSImmutableColor: 0x600000c66800> (C10CE689-E370-4BBC-9EE8-B4BE54858E53)";
    NSFont = "\"Arial-BoldMT 13.00 pt. P [] (0x604000c46840) fobj=0x7fbb0e18fad0, spc=3.61\"";
    NSParagraphStyle = "Alignment 0, LineSpacing 0, ParagraphSpacing 0, ParagraphSpacingBefore 0, HeadIndent 0, TailIndent 0, FirstLineHeadIndent 0, LineHeight 0/0, LineHeightMultiple 0, LineBreakMode 0, Tabs (\n    28L,\n    56L,\n    84L,\n    112L,\n    140L,\n    168L,\n    196L,\n    224L,\n    252L,\n    280L,\n    308L,\n    336L\n), DefaultTabInterval 0, Blocks (\n), Lists (\n), BaseWritingDirection -1, HyphenationFactor 0, TighteningForTruncation NO, HeaderLevel 0";
    textStyleVerticalAlignmentKey = 0;
}, 
selector=string>

Pay attention to NSFont = "\"ArialMT... and NSFont = "\"Arial-BoldMT....

From that object you can find NSFont that contains bold weight of selected text layer.
Note that you have to find which weight is the bold weight for the font though.

Maybe you can do something similar to what I'm doing in my plugin here.

NSFontManager.sharedFontManager().convertFont_toHaveTrait(layer.font(), 2);

You can compare the paragraph style retrieved earlier to the bold font attribute you retrieved from code right above.

Hope this helps.
Cheers.

from bold-it.

ysjn avatar ysjn commented on August 11, 2024

Great! I'm closing this issue but feel free to reopen if you need.
Looking forward to hearing your findings, good luck! 👍

from bold-it.

Related Issues (4)

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.