开发者

Convert a .rtf into a mac .r resource, in a scriptable way

I currently have a SLA in a .rtf format, which is to be integrated into .dmg using the intermediary .r mac resource format, which is used by the Rez utility. I had already done it by hand once, but updates made to the .rtf file are overwhelming to propagate to the disk image, and error-prone. I would like to automate this task, which could also help adding other languages or variants.

How cou开发者_如何学Cld the process of .rtf to .r text conversion be automated?

Thanks.


Only because I didn't fully understand how the accepted answer actually achieved the goal, I use a combination of a script to generate the hex encoding:

#!/usr/bin/env ruby
# Makes resource (.r) text from binaries.

def usage
  puts "usage: #{$0} infile"
  puts ""
  puts "  infile   The file to convert (the output will go to stdout)"
  exit 1
end

infile = ARGV[0]    || usage

data = File.read(infile)
data.bytes.each_slice(16) do |slice|
  hex = slice.each_slice(2).map { |pair| pair.pack('C*').unpack('H*')[0] }.join(' ')

  # We could put the comments in too, but it probably isn't a big deal.
  puts "\t$\"#{hex}\""
end

The output of this is inserted into a variable during the build and then the variable ends up in a template (we're using Ant to do this, but the specifics aren't particularly interesting):

data 'RTF ' (5000, "English SLA") {
@english.licence@
};

The one bit of this which did take quite a while to figure out is that 'RTF ' can be used for the resource directly. The Apple docs say to separately insert 'TEXT' (with just the plain text) and 'styl' (with just the style). There are tools to do this of course, but it was one more tool to run and I could never figure out how to make hyperlinks work in the resulting DMG. With 'RTF ', hyperlinks just work.

Hoping that this saves someone time in the future.


Use the unrtf port (from macports), then format the lines, heading and tail with a shell script.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜