NISUS Archives

February 2011

NISUS@LISTSERV.DARTMOUTH.EDU

Options: Use Monospaced Font
Show Text Part by Default
Show All Mail Headers

Message: [<< First] [< Prev] [Next >] [Last >>]
Topic: [<< First] [< Prev] [Next >] [Last >>]
Author: [<< First] [< Prev] [Next >] [Last >>]

Print Reply
Subject:
From:
Reply To:
Date:
Sat, 12 Feb 2011 17:46:02 +0900
Content-Type:
text/plain
Parts/Attachments:
text/plain (103 lines)
On 2011-02-10 [+0900 JST], at 3:48 AM, Bob Stern wrote:

> Also, thanks again for the "Find all fonts in the document" macro you posted a long time ago.  I use it frequently when importing documents created on other computers.

Glad to know my macro (I think it is the one originally named 'Select by Font') serves you. For my part, I'm using it mainly for the conversion in the opposite direction: change fonts in my documents I have to send to Windows users.

Anyway, it is tedious to use that macro for such a purpose when there are several fonts to be replaced. So I wrote a macro for replacing a set of fonts with another set.
<http://www2.odn.ne.jp/alt-quinon/files/NWPro/convert/RemapFonts_20110212_nwm.zip>

Fonts defined in the conversion table ($fontMap below and in the uploaded macro file) is just a sample. I don't know well what Apple fonts can be treated as equivalents of MS fonts. 


Kino

--

### Remap Font ###

# Change fonts in the frontmost document to those defined on the right
# side of $fontMap.

# If the font change failed, for example, due to a typo in font name
# in $fontMap, you will see 'Courier New > Courier (failed!)'
# or something alike in the Exit dialog when the macro has finished to run.

# With '$reversed = true', the font change will be done in the opposite
# direction. I.e. fonts on the right side of $fontMap will changed to
# those on the left side.

$reversed = false

$fontMap = Hash.new
$fontMap{'Times New Roman'} = 'Times'
$fontMap{'Arial'} = 'Helvetica'
$fontMap{'Courier New'} = 'Courier'
$fontMap{'Comic Sans MS'} = 'Chalkboard'
$fontMap{'Trebuchet MS'} = 'Futura'
$fontMap{'Georgia'} = 'Baskerville'
$fontMap{'Verdana'} = 'Gill Sans'
$fontMap{'MS Mincho'} = 'Hiragino Mincho ProN'
$fontMap{'MS Gothic'} = 'Hiragino Kaku Gothic ProN'

if $reversed == true
	foreach $key, $value in $fontMap
		$fontMap{$value} = $key
		$fontMap.removeKey $key
	end
end

$sep = ' > '

$doc = Document.active
if $doc == undefined
	exit
end

$selectionsByFont = Hash.new
foreach $text in $doc.allTexts
	if $text.length
		$i = 0
		while $i < $text.length
			$range = $text.rangeOfDisplayAttributesAtIndex $i
			$fontFamilyName = $text.displayAttributesAtIndex($i).fontFamilyName
			if $text.displayAttributesAtIndex($i).isFontMissing
				$originalFont = $text.attributesAtIndex($i).fontFamilyName
				if Defined $fontMap{$originalFont}
						$fontFamilyName = $originalFont
				end
			end
			if Defined $fontMap{$fontFamilyName}
				if $selectionsByFont{$fontFamilyName} == undefined
					$selectionsByFont{$fontFamilyName} = Array.new
				end
				$sel = TextSelection.new $text, $range
				$selectionsByFont{$fontFamilyName}.appendValue $sel
			end
			$i = $range.bound
		end
	end
end

if $selectionsByFont.keys.count
	$results = Array.new
	foreach $fontFamilyName in $selectionsByFont.keys
		if Defined $selectionsByFont{$fontFamilyName}
			Push Target Selection $selectionsByFont{$fontFamilyName}
				$success = Set Font Name $fontMap{$fontFamilyName}
			Pop Target Selection
			$result = $fontFamilyName.textByAppending $sep, $fontMap{$fontFamilyName}
			if ! $success
				$result &= ' (failed!)'
			end
			$results.appendValue $result
		end
	end
	$results.sort 'li'
	$results.prependValue 'Fonts Replaced:'
	exit $results.join("\n")
else
	exit 'No font to be replaced found, exiting…'
end

### end of macro ###

ATOM RSS1 RSS2