Friday, September 16, 2005


Text Processing -- Preserve Symbols

This job I'm doing involves a lot of Greek alphabetic characters which I have dubbed "symbols" because originally the Symbol font was used to present them. While the text font I've selected for the job, Myriad Pro, has all the glyphs I need, they are designed (not unexpectedly) to match the general look and feel of the Myriad family. As a result, the lowercase kappa looks entirely too much like a small cap K and the lowercase alpha looks more like a lowercase A. So, I'm proposing to my client that we use Warnock Pro as the source of our Greek alphabet.

Now we come to an acid test. What will those characters look like here if I just copy and paste them from my unicode script. There's only one way to find out:
function preserveSymbols(theText) {
 try {
  //This will fail if the Symbol style does not exist already
  var myCharStyle = myDoc.characterStyles.item('Symbol');
  var mySymbols = ["κ","µ","α","β","δ","Δ","ζ","γ","ε","λ"]
  app.findPreferences = null;
  app.changePreferences = null;
  for (var j=0; mySymbols.length > j; j++) {[j],false,false,undefined,{},{appliedCharacterStyle:myCharStyle})
  return true
 } catch (e) {
  myErr = myErr + "Document lacks a Symbol character style.\r";
  return false
Looks good so far in this editing window and in the preview. I wonder if all browsers are suitably equipped. Let me know if you can't read them. Perhaps I could come up with HTML codes for them, except that I'm not sure I know what they're all called. Actually, it's only the seventh one that is a mystery to me. I picked this list up from a script I wrote the last time I did this catalog, which was about two years ago so it is no wonder I have forgotten some details.

Notice how this function joins in the myErr procedure to report that the Symbol character style is missing -- sure, the script could create it, but the way this job is supposed to work that style is supposed to be there; if it isn't, that reflects a serious problem, so better to report it than try to fix it and perhaps mask some other issue.

It occurs to me that I have done enough work on the main routine to take a look at that. Here's how it stands:
myLib = getProjectLibrary("B-Library.indl");
myDoc = app.activeDocument;
myErr = "";
var myStory = myDoc.stories[0];
if (myStory.tables.length > 0) {
 var myTable = myStory.tables[0];
 if (!applyParaStyles(myTable)) { errorExit(myErr) }
if (!preserveSymbols(myStory)) { errorExit(myErr) }
Notice how I only convert the table if it's there. That's for testing purposes. It allows me to add functionality to the post-table text processing and continue incremental testing without having to revert to the original file every time.

So far so good. This new function did its job.

I'm pleased to see that the Greek glyphs are present when I view the blog using Safari.
Post a Comment

<< Home

This page is powered by Blogger. Isn't yours?