Formatting fields and exporting as RTF?

Need help with a script? This is the place to discuss how to get your code running!

Formatting fields and exporting as RTF?

Postby Mike » Tue Jan 16, 2018 7:28 pm

Is it possible to set up a field in SuperCard (either manually or by script) with tabs set at particular points, put tab delimited information into that field, and then export that field as an RTF file which would maintain the proper tab positions?
Mike Yenco
YENCO.COM
User avatar
Mike
 
Posts: 215
Joined: Sun Jul 06, 2008 8:54 am
Location: Massachusetts, USA

Re: Formatting fields and exporting as RTF?

Postby vinnie-bob » Wed Jan 17, 2018 10:26 am

I was actually wondering the same thing, Mike. And if not, please add as feature request. Would be great to be able to export such a field with all its formating to an RTF file.
------
vince
------
User avatar
vinnie-bob
 
Posts: 229
Joined: Sun Jul 06, 2008 10:55 am
Location: Des Moines, Iowa, USA

Re: Formatting fields and exporting as RTF?

Postby codegreen » Wed Jan 17, 2018 9:21 pm

Currently SC implements only the WASTE 2.0 fixed (i.e., single) width tabs.

Individually adjustable tabs were under construction in the last 2.1 beta, but weren't soup yet when Apple cut the knees out from under it.

However AFAIK exporting 4.6+ fixed tabs to RTF should work...

-Mark
codegreen
 
Posts: 1529
Joined: Mon Jul 14, 2008 11:03 pm

Re: Formatting fields and exporting as RTF?

Postby codegreen » Wed Jan 17, 2018 9:59 pm

And of course if you wanted it badly enough you could go back and edit the 'fixed' tab stops (IIRC expressed in twips) in the generated RTF (either manually or programmatically) to adjust the position of the exported tabs however you please.

-Mark
codegreen
 
Posts: 1529
Joined: Mon Jul 14, 2008 11:03 pm

Re: Formatting fields and exporting as RTF?

Postby Mike » Wed Jan 17, 2018 10:00 pm

Hi Mark,

Yes, this is pretty much what I found when trying this out. For some reason I thought I remembered a Ruler CDEF or something that was available for WASTE that included being able to drag left, right, center, decimal tabs to the ruler and position them independently of each other. I think I probably transposed such a thing being available (or at least seeing a picture of it at the time) to it being available in SuperCard. I would imagine that even if it was available that was no guarantee that it would have been in SuperCard as there would have been being able to script it as a consideration vs. just the visual manual setting of tabs in the ruler. Unfortunately, the tab delimited data I was thinking about putting into such a field and exporting has (mostly) longer strings in the first item, and shorter strings in two or three items after that so the single fixed width tabs (set with tabSize) won't really do what I was hoping for.

I did test out the export text syntax and you are correct, the (single fixed width) tabs are correctly exported to the RTF. So close, yet so far. I was hoping to use this with your excellent printRTF external as a quick and easy way to print some data nicely formatted into columns. But, now that I think about it, I also recall some issue with whatever API is used for printRTF where it doesn't honor the font size of the RTF files... and that would have further complicated matters even if I had been able to put this together as I probably would have needed to print the data in 9 or 10 point to be practical and I think the external just prints everything at 12 point IIRC.
Mike Yenco
YENCO.COM
User avatar
Mike
 
Posts: 215
Joined: Sun Jul 06, 2008 8:54 am
Location: Massachusetts, USA

Re: Formatting fields and exporting as RTF?

Postby codegreen » Thu Jan 18, 2018 8:45 am

WASTE 2.1 and that ruler control are capable of creating and displaying variable tabs, and IIRC this was implemented in late versions of the 2.1 WASTE Demo app, so you might've seen it there. However since underlying support for variable tabs is missing in the WASTE version SC uses, that feature is disabled in the SC field ruler.

-Mark
codegreen
 
Posts: 1529
Joined: Mon Jul 14, 2008 11:03 pm

Re: Formatting fields and exporting as RTF?

Postby codegreen » Thu Jan 18, 2018 10:57 am

Here's a quick snippet that shows how to tail-patch the tab stops in RTF exported from fields:

Code: Select all
on mouseUp
  local filePath = posixToHFS("~/Desktop") & ":Testo.rtf"
  open file filePath
  write setFldRtfTabStops(the rtfText of cd fld 1, 108, 216, 288) to file filePath
  close file filePath
  launch filePath
end mouseUp

function setFldRtfTabStops inRTF, inTabList
  if inRTF starts with "{\rtf1\mac" then
    set the lineDel to linefeed
    enum tabLine = lineOffset("{\pard", inRTF)
    if tabLine > 0 then
      local outTabList = ""
      repeat with i = 2 to paramCount()
        get param(i)
        if isNumber(it) then put "\tx" & it * 20 after outTabList
      end repeat
      get word 1 of line tabLine of inRTF
      put outTabList into char offset("\tx", it) to 999999 of ¬
        word 1 of line tabLine of inRTF
    end if
  end if
  return inRTF
end setFldRtfTabStops

If you've assigned multiple paragraph styles to a field you'll need to wrap the guts of this in something that walks through them to find and chew on just the one(s) of interest.

HTH,
-Mark
codegreen
 
Posts: 1529
Joined: Mon Jul 14, 2008 11:03 pm

Re: Formatting fields and exporting as RTF?

Postby Mike » Thu Jan 18, 2018 12:22 pm

Instead of using a SuperCard field, exporting as RTF, and then trying to change the tab positions or type (left, right, center, decimal), is there a way I can start with an .rtf file in TextEdit with the ruler set up the way I want. Use fileCopy to make a copy of that .rtf file and then inject the data* into the resulting .rtf directly?

*Data is item delimited with tab and line delimited with cr.
Mike Yenco
YENCO.COM
User avatar
Mike
 
Posts: 215
Joined: Sun Jul 06, 2008 8:54 am
Location: Massachusetts, USA

Re: Formatting fields and exporting as RTF?

Postby Mike » Thu Jan 18, 2018 12:49 pm

OK, looks like I figured out a way to do it. I created an .rtf file in TextEdit with the ruler set up the way I want. I filled in a couple lines of data. I then opened the file in SuperCard and read from it. I put the resulting data into a userProp. If I then copy all the text just to the point before my placeholder data and save that as a template in a userProp... I can then grab my item (tab delimited), line (cr delimited) data, check if the last char = cr and if it isn't add a cr after my data. Then replace cr in my data with "\" & linefeed. Put "}" after my data. Open a file, write my template & data to it, close the file and... voila.
Mike Yenco
YENCO.COM
User avatar
Mike
 
Posts: 215
Joined: Sun Jul 06, 2008 8:54 am
Location: Massachusetts, USA

Re: Formatting fields and exporting as RTF?

Postby codegreen » Thu Jan 18, 2018 1:45 pm

Though I haven't tried it here, I think that should actually be much easier.

You can't assign variable tab stops to nothing in TextEdit, so you'll have to put in (at a minimum) a line of 'prototype' text (a run of tab-delimited "X"s should do) to hang them on.

You'll also have to 'pre-cook' your data by inserting a backslash before each return.

Then just read the template file, use replace() to swap your data for the prototype string, and write it back out to another file.

-Mark
codegreen
 
Posts: 1529
Joined: Mon Jul 14, 2008 11:03 pm


Return to Scripting in SuperTalk

Who is online

Users browsing this forum: No registered users and 3 guests