Styled Text Library - Getting RGB from style data
Styled Text Library - Getting RGB from style data
- Subject: Styled Text Library - Getting RGB from style data
- From: Malcolm Fitzgerald <email@hidden>
- Date: Sun, 10 Mar 2002 22:37:46 +1100
Arthur,
I'm starting to play with the styled text scripts that you sent. They're
working quite well enough for the simple, small pieces of styled text that I
need to convert.
I ran foul of your color-conversion hack though. Your notes describe the
work around that you generated (see below). Your example used a nice
web-safe colour and you were able to avoid seeing the errors that would
develop. I used a red, green and blue from Smile's "Text->Color->" menu and
it's style record looked like this:
{string:"Green", scrap styles:+data
styl000100000000001800120003000000120000800011B0;}
Your "item 2 of" hack produced all sorts of odd results. In this instance,
ie, green, Item 2 of the red and blue values was much greater than item 2 of
the green value, though item 1 of the green value was much greater than item
1 of the red and blue values. After looking at the problem for a little
while I tried changing item 2 to item 1 (shrug). I knew that wasn't good
enough though and set to work. I finally realised that applescript's RGB
color class wants numbers between 0-65535 and that two bytes were needed.
Web safe colours couldn't be assured, but accuracy would be.
Passing the HexToInt funtion two bytes at a time produces the correct
results: RGB Color {0,32768,4528} HTML "#008011" from the data above. The
RGB2HTML function in the applescript guidebook did the rest. Maybe there's a
way to round out to web-safe but I'm not bothering to do that. I really only
need to test for blue values because blue, underlined text is the signal to
construct an HREF.
-- in line comments below
-- hexString == hex-string of exactly 40 characters,
-- representing one style-run in a style
-- record.
--
-- hexString == "000000330012000D0004034C000F00003333FFFF"
--
-- byte separated ==
-- 00 00 00 33 00 12 00 0D 00 04 03 4C 00 0F 00 00 33 33 FF FF
--
-- byte codes ==
-- 0 0 0 51 0 18 0 13 0 4 3 76 0 15 0 0 51 51 255 255
-- ??? The color info in these contains more data than
-- in a web hexidecimal triplet. I need to research a
-- correct conversion process. "Web-safe" colors seem
-- to always be the hex-triplet doubled, ie:
--
-- <body bgcolor="#00AAFF">
--
-- translates in RGB to
--
-- 0000AAAAFFFF
--
-- so my "hack" is to just grab one of the two integers
-- of the RGB, (this is why I chose to store them as two
-- integers from 2 bytes, rather than as one integer from
-- a short).
--
--
yours
Malcolm Fitzgerald
Database Manager
The Australian Society of Authors
ph:02 93180877
fax:02 93180530 email@hidden
http://www.asauthors.org
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.