FontLab Forum
2012-05-22, 21:41:22 *
Welcome, Guest. Please login or register.

Login with username, password and session length
News: Welcome to the FontLab forum, read how to use it! Update: Archives from old MSN forums are now available on our forum.
 
   Home   Help Search Calendar Downloads Tags Login Register  
Del.icio.us Digg FURL FaceBook Stumble Upon Reddit SlashDot

Pages: [1]
  Print  
Author Topic: calt problem: substitute multiple figures *before* cap by smallcap figures  (Read 1472 times)
mekkablue
Beta: FontLab Studio Mac
Hero Member
***

Karma: +0/-0
Austria Austria

Posts: 40



WWW
« on: 2011-03-21, 12:42:25 »

I implemented a calt feature where all caps are replaced by smallcaps as soon as at least two caps follow each other (needs to be done for a special application, I'll spare you the details).
So, /A/B/C is transformed into /A.sc/B.sc/C.sc -- this works.

But now I need to add this functionality with figures. Any figures before and after caps must be transformed:

1. /one/A --> /one.sc/A.sc
2. /one/two/three/A --> /one.sc/two.sc/three.sc/A.sc
3. /A/one/two --> /A.sc/one.sc/two.sc
4. /one/two --> /one/two (must stay the same)


This is what I've got so far:
Code:
lookup CAFT {
# Replace any cap following another cap or smallcap with smallcap:
sub [@SMALLCAPS @CAPS @FIGURES] @CAPS' by @SMALLCAPS;
sub [@SMALLCAPS @CAPS @FIGURES_SMALLCAPS] @FIGURES' by @FIGURES_SMALLCAPS;
} CAFT;

lookup CBFR {
# Replace any cap before a smallcap (or figure) with smallcap:
sub @CAPS' [@SMALLCAPS @FIGURES] by @SMALLCAPS;
sub @FIGURES' [@SMALLCAPS @FIGURES_SMALLCAPS] by @FIGURES_SMALLCAPS;
} CBFR;

Result: (1.) and (3.) work, but (2.) doesn't.
How can I make (2.) work as well? It should work for an arbitrary number of figures.
Note: Because of (4.), I cannot simply add the figures to the @CAPS and @SMALLCAPS classes.

Anyone?
TIA, Eric.
Logged
Arno Enslin
Hero Member
*****

Karma: +8/-0
Germany Germany

Posts: 98



« Reply #1 on: 2011-03-23, 07:16:06 »

I dislike it not to have the vfb and feature file, when I analyze OT code, but I have tried it anyway. The last time I wrote OT code was round about a year ago; and I am tired and cannot concentrate at the moment. So please excuse, if it does not work. Your explanation and your comments in the code are a bit irritating. With caps and smallcaps you also seem to mean figures and figure small caps. And it seems, that you also want to substitute input combinations like A.sc/A/A.sc.

Code:
sub [@SMALLCAPS @CAPS @FIGURES_SMALLCAPS @FIGURES] [@CAPS @FIGURES]' by [@SMALLCAPS @FIGURES_SMALLCAPS];
sub [@CAPS @FIGURES]' [@SMALLCAPS @CAPS @FIGURES_SMALLCAPS @FIGURES] by [@SMALLCAPS @FIGURES_SMALLCAPS];

Edited:

I just recognize, that (4.) would not work.

Maybe it works with a class, that contains those characters, that are not smallcaps or caps in combination with an ignore-rule.

But as I said, it is uncomfortable to analyze code, if you cannot try it out.
« Last Edit: 2011-03-23, 14:37:22 by Arno Enslin » Logged
Arno Enslin
Hero Member
*****

Karma: +8/-0
Germany Germany

Posts: 98



« Reply #2 on: 2011-03-23, 19:40:29 »

You need an additional class "neitherCaps_norSmallCaps_but_everything_else" (with a shorter name), but this should work now, although my instinct says, that it is overcomplicated / that the problem can be solved more elegant.

Code:
feature calt {
ignore sub  @FIGURES' @CAPS @neitherCaps_norSmallCaps_but_everything_else;
sub [@SMALLCAPS @CAPS] @CAPS' by @SMALLCAPS;
sub [@SMALLCAPS @FIGURES_SMALLCAPS] @FIGURES' by @FIGURES_SMALLCAPS;
sub [@CAPS @FIGURES]' [@SMALLCAPS @CAPS] by [@SMALLCAPS @FIGURES_SMALLCAPS];
sub @FIGURES' [@SMALLCAPS @CAPS @FIGURES_SMALLCAPS] by @FIGURES_SMALLCAPS;
lookup THIS {
sub @FIGURES' @FIGURES_SMALLCAPS by @FIGURES_SMALLCAPS;
sub @FIGURES_SMALLCAPS @FIGURES' by @FIGURES_SMALLCAPS;
} THIS;
} calt;
Logged
mekkablue
Beta: FontLab Studio Mac
Hero Member
***

Karma: +0/-0
Austria Austria

Posts: 40



WWW
« Reply #3 on: 2011-03-24, 11:04:42 »

Thank you Arno,

But there is one inherent weakness in using a @neither_nor class, namely it doesn't work at the beginning/the end of a line ... simply because there is no preceding/following glyph I could put into the class.

Also, the main problem remains: substituting an arbitrary number of glyphs directly preceding a certain other glyph. I think this cannot be done in feature code. I think this is a similar issue as the one Read Roberts describes here.

My second best solution is as follows. I don't replace an arbitrary number of figures before a cap, but up to six. In other words, starting from one million, the figures will not be replaced anymore. This is my code:

feature calt {
   sub [@smallcaps @caps @figures_smallcaps @figures] @caps' by @smallcaps;
   sub [@smallcaps @caps @figures_smallcaps] @figures' by @figures_smallcaps;

   lookup befr {
      sub @caps' [@smallcaps @caps @figures @figures_smallcaps] by @smallcaps;

      ignore sub @figures @figures';
      sub @figures' @figures @figures @figures @figures @figures @figures [@smallcaps @caps] by @figures_smallcaps;
      sub @figures' @figures @figures @figures @figures @figures [@smallcaps @caps] by @figures_smallcaps;
      sub @figures' @figures @figures @figures @figures [@smallcaps @caps] by @figures_smallcaps;
      sub @figures' @figures @figures @figures [@smallcaps @caps] by @figures_smallcaps;
      sub @figures' @figures @figures [@smallcaps @caps] by @figures_smallcaps;
      sub @figures' @figures [@smallcaps @caps] by @figures_smallcaps;
      sub @figures' [@smallcaps @caps] by @figures_smallcaps;
   } befr;
} calt;


It acts as follows:

1. /one/A --> /one.sc/A.sc
2. /one/two/three/A --> /one.sc/two.sc/three.sc/A.sc ...and so on, see (5.) and (6.)
3. /A/one/two --> /A.sc/one.sc/two.sc
4. /one/two --> /one/two (must stay the same)
5. /one/two/three/four/five/six/A --> /one.sc/two.sc/three.sc/four.sc/five.sc/six.sc/A.sc
6. /one/two/three/four/five/six/seven/A --> /one/two/three/four/five/six/seven/A (stays the same)

Logged
Arno Enslin
Hero Member
*****

Karma: +8/-0
Germany Germany

Posts: 98



« Reply #4 on: 2011-03-24, 12:33:23 »

Yes, I also had discovered a bug in my code and wondered, whether OT code is complex enough for solving your problem. I would also think about, what input you expect – the maximum length of a string, for which the feature shall work. Your code actually would substitute the characters after the small letters in this string:

/A/A/a/b/c/zero/A

and even in these, although I thought, that you only want to cover those strings, in which at least one capital or small capital follows another one:

/A/a/b/c/zero/A

and

/zero/A

Edited:

Probably a misunderstanding because of the different meanings of caps in your initial destription and their meaning with regard to the classes.

Edited 2:

May it be, that this line is not needed, because it catches none of the following rules?:
ignore sub @figures @figures';
« Last Edit: 2011-03-24, 13:17:36 by Arno Enslin » Logged
mekkablue
Beta: FontLab Studio Mac
Hero Member
***

Karma: +0/-0
Austria Austria

Posts: 40



WWW
« Reply #5 on: 2011-03-25, 05:17:52 »

You are right. I assume to /A/A/a/b/c/zero/A and /A/a/b/c/zero/A to be an acceptable collateral damage in this case, though. In any event, /zero/A is intended to be transformed to SC. Sorry for any unclarities. It is a rather complex problem to describe, it seems.

The ignore rule is needed because if the chain of figures before the cap is longer than six, none of them should be transformed. If there are up to six figures, all of them should be transformed. Your second reply in this thread gave me the idea.

Thank you!
Logged
Tags:
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF | SMF © 2011, Simple Machines Valid XHTML 1.0! Valid CSS!