Upside Down Text

I am intrigued by the iPhone app Feathers by naklab (http://feathersapp.com) and its ability to create upside down text. After doing a little searching, I found several sites that add insight into what’s going on (http://www.fileformat.info/convert/text/upside-down.htm).

This appears to be a perfect job for Applescript. Anyone want to polish this script into something more, maybe adding upper case letters, etc.?


-- modified Apple's change case subroutine
set this_text to "upside down text... awesome!"
flip_text(this_text)

on flip_text(this_text)
	set the comparison_string to "abcdefghijklmnopqrstuvwxyz.!?\",&$"
	set the source_string to "ɐqÉ”pǝɟƃɥıɾʞʃɯuodbɹsʇnʌʍxÊŽzË™¡¿ž'â…‹$"
	set the new_text to ""
	repeat with this_char in this_text
		set x to the offset of this_char in the comparison_string
		if x is not 0 then
			set the new_text to (character x of the source_string & the new_text) as string
		else
			set the new_text to (this_char & the new_text) as string
		end if
	end repeat
	return the new_text
end flip_text

Just for the hell of it, a faster version for AS 2.0 or later:

set this_text to "upside down text... awesome!"
flip_text(this_text)

on flip_text(this_text)
	set comparison_ids to id of "abcdefghijklmnopqrstuvwxyz.!?\",&$"
	-- Upside-down equivalents of character ids 33 thru 122
	set source_ids to {161, 8222, missing value, 36, missing value, 8523, missing value, missing value, missing value, missing value, missing value, 39, missing value, 729, missing value, missing value, missing value, missing value, missing value, missing value, missing value, missing value, missing value, missing value, missing value, missing value, missing value, missing value, missing value, missing value, 191, missing value, missing value, missing value, missing value, missing value, missing value, missing value, missing value, missing value, missing value, missing value, missing value, missing value, missing value, missing value, missing value, missing value, missing value, missing value, missing value, missing value, missing value, missing value, missing value, missing value, missing value, missing value, missing value, missing value, missing value, missing value, missing value, missing value, 592, 113, 596, 112, 477, 607, 387, 613, 305, 638, 670, 643, 623, 117, 111, 100, 98, 633, 115, 647, 110, 652, 653, 120, 654, 122}
	
	set text_ids to id of this_text
	repeat with this_id in text_ids
		if (this_id is in comparison_ids) then set this_id's contents to item (this_id - 32) of source_ids
	end repeat
	
	return character id (reverse of text_ids)
end flip_text

I generated the source_ids list from Rob’s strings:

set the comparison_string to "abcdefghijklmnopqrstuvwxyz.!?\",&$"
set the source_string to "ɐqÉ”pǝɟƃɥıɾʞʃɯuodbɹsʇnʌʍxÊŽzË™¡¿ž'â…‹$"

set source_ids to {}
repeat with i from 33 to 122
	set end of source_ids to missing value
end repeat

repeat with i from 1 to (count comparison_string)
	set this_id to id of character i of comparison_string
	set item (this_id - 32) of source_ids to id of character i of source_string
end repeat

source_ids

Nigel, I found a bug in your script! :o - NEVER!

If you put in “L”, it returns, well, “L”. Rob’s Script is fine though. :wink:

Hi, Dylan.

Thanks. Not so much a bug as an “incompleteness”. :wink: Neither Rob’s script nor mine (which was based on it) claims to work with upper-case letters. The side-effect with Rob’s method ” when using AppleScript’s default text attribute ‘ignoring case’ ” is that upper-case letters are replaced with upside-down lower-case letters. The effect with mine is that upper-case letters are left as they are. If you put the call to Rob’s handler in a "considering case’ statement, upper-case letters will remain unchanged there too.

That last sentence was going to end “. the two handlers will return exactly the same results.” But while checking it out just now, I noticed that Rob’s script reverses the order of characters too, which I’d missed before. I’ve now inserted a ‘reverse’ into my own script to match it. :rolleyes: