Create one string with different fonts?

Is there a way to create one string with different fonts? I need this for a pasteboard.copy

font(MyFont1)
Text = "MyText \
"
font(MyFont2)
Text = Text.."MyText Line 2"
Pasteboard.copy(Text)

Returns text with the font(MyFont2)

As far as I know, that’s not possible. Text is displayed on the screen based on the last font command. Text doesn’t go into a string as different fonts.

@FearMe2142 - this may help, but I haven’t tried it

https://stackoverflow.com/questions/12789507/copy-text-with-formatting-ios-6-nsattributedstring-to-pasteboard

But if creating a table for each letter? @FearMe2142, search for
Markdown - there is a code by @yojimbo2000 (I think) how to make a styling.

@FearMe2142 this is how you do rich text formatting in Codea:

https://codea.io/talk/discussion/6710/markdown-codea-rich-text-formatting

@FearMe2142 Here’s something I posted long ago that shows text in different colors using a table of colors. You specify the x,y and width of the text field. To show different fonts, I just added a font table. But as I said above, the string doesn’t have text of different fonts or colors in it, it’s only when it shown on the screen that it’s displayed in different colors or fonts. Another table for font size could be added also. I’m only using one control character now, but I would need three to control color, font, and font size.

@dave1707, @yojimbo2000 - I think the question was how you put formatted text on the pasteboard (rather than draw it on the screen).

I was going to say that being able to copy text with different formatting is a potential security risk (you could hide text in a string that way) but then I read this: https://developer.apple.com/library/ios/documentation/StringsTextFonts/Conceptual/TextAndWebiPhoneOS/UsingCopy,Cut,andPasteOperations/UsingCopy,Cut,andPasteOperations.html and discovered that it is technically possible. But I don’t know if Codea allows for it.

Sorry, I was in such a hurry to leave that I forgot to post the code for my comment above. I think the only way to put formatted text on the pasteboard is to have control characters imbedded in the text and then use that when the text is shown, similar to what I show here.

EDIT: Changed the code so that the colors and fonts use different control characters.

displayMode(FULLSCREEN)

function setup()
    print(font())
    textMode(CORNER)
    str="¥a£dThis ¥cis an example of ¥ddiff¥ae£frent ¥cfonts and colors of ¥dtext. £cYou ¥bcan setup ¥aas many different ¥dfonts and colors as you want. You £ecan pick ¥athe screen ¥dx,y position and ¥ethe width to print. The fonts and colors are ¥ajust a £bmatter ¥dof creating ¥dlarger tables £afor them ¥dand adding ¥fmore control ¥bcharacters."
    
    fon={a="HelveticaNeue",
         b="Baskerville-Italic",
         c="GillSans-Italic",
         d="HoeflerText-Italic",
         e="Noteworthy-Light",
         f="SnellRoundhand" }
    
    col={a=color(255,0,0),
         b=color(0,255,0),
         c=color(0,0,255),
         d=color(255,255,0),
         e=color(0, 238, 255, 255),
         f=color(255, 0, 223, 255),
        }
end

function draw()
    background(86, 118, 106, 255)
    fill(255)
    showText(100,500,500)
    showText(500,300,150)
    showText(200,700,300)
end

function showText(x,y,size)
    local count, xoffset, yoffset=0,0,0
    for z=1,str:len() do
        local b1,b2=str:byte(z,z+1)
        if count==0 then
            local ch=str:sub(z,z)
            if b1==194 then
                count=2
                if b2==165 then
                    fill(col[str:sub(z+2,z+2)])
                elseif b2==163 then
                    font(fon[str:sub(z+2,z+2)])
                end
            else
                text(ch,x+xoffset,y-yoffset)
                local w,h=textSize(ch)
                xoffset = xoffset + w
                if xoffset>size then
                    xoffset=0
                    yoffset = yoffset + h
                end
                count=0
            end
        else
            count=count-1
        end
    end
end