0 Replies
      Latest reply on Feb 13, 2020 12:52 AM by rkorez
      rkorez Level 1 Level 1 (0 points)

        Can anyone please help me understand NSTextStorage attributes.

        Let say we have an attributed bold text which looks like this:

         

        bold{
            NSColor = "Generic RGB colorspace 1 1 1 1";
            NSFont = "\"OpenSans-Bold 16.00 pt. P [] (0x100cca530) fobj=0x100f2d710, spc=4.16\"";
            NSParagraphStyle = "Alignment 4, LineSpacing 0, ParagraphSpacing 8, ParagraphSpacingBefore 16, HeadIndent 0, TailIndent 0, FirstLineHeadIndent 0, LineHeight 26/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 YES, HeaderLevel 0 LineBreakStrategy 0";
        }

        After editing, it looks like this

         

        bold{
            NSColor = "Generic RGB colorspace 1 1 1 1";
            NSFont = "\"OpenSans-Bold 16.00 pt. P [] (0x100cca530) fobj=0x100f2d710, spc=4.16\"";
            NSParagraphStyle = "Alignment 4, LineSpacing 0, ParagraphSpacing 8, ParagraphSpacingBefore 16, HeadIndent 0, TailIndent 0, FirstLineHeadIndent 0, LineHeight 26/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 YES, HeaderLevel 0 LineBreakStrategy 0";
        }a{
            NSColor = "Generic RGB colorspace 1 1 1 1";
            NSFont = "\"OpenSans-Bold 16.00 pt. P [] (0x100cca530) fobj=0x100f2d710, spc=4.16\"";
            NSParagraphStyle = "Alignment 4, LineSpacing 0, ParagraphSpacing 8, ParagraphSpacingBefore 16, HeadIndent 0, TailIndent 0, FirstLineHeadIndent 0, LineHeight 26/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 YES, HeaderLevel 0 LineBreakStrategy 0";
        }s{
            NSColor = "Generic RGB colorspace 1 1 1 1";
            NSFont = "\"OpenSans-Bold 16.00 pt. P [] (0x100cca530) fobj=0x100f2d710, spc=4.16\"";
            NSParagraphStyle = "Alignment 4, LineSpacing 0, ParagraphSpacing 8, ParagraphSpacingBefore 16, HeadIndent 0, TailIndent 0, FirstLineHeadIndent 0, LineHeight 26/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 YES, HeaderLevel 0 LineBreakStrategy 0";
        }d{
            NSColor = "Generic RGB colorspace 1 1 1 1";
            NSFont = "\"OpenSans-Bold 16.00 pt. P [] (0x100cca530) fobj=0x100f2d710, spc=4.16\"";
            NSParagraphStyle = "Alignment 4, LineSpacing 0, ParagraphSpacing 8, ParagraphSpacingBefore 16, HeadIndent 0, TailIndent 0, FirstLineHeadIndent 0, LineHeight 26/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 YES, HeaderLevel 0 LineBreakStrategy 0";

        If we now try to get longest effective range from the text store using attributes(at:longestEffectiveRange:in:), we will only get the range of a "bold" part of a text.

        Why is that and how can I fix this, since I need to know the actual longest range and not the range of the attribute run?