10.3 Font Styles

<..load font styles..>
 int length = fileName.length();
 int loc = fileName.indexOf(fileName.charAt(length-1));
 fileName = fileName.substring(loc+1,length-1);
 try{
    String s = "";
    FileReader fr  = new FileReader( fileName );
    BufferedReader in = new BufferedReader( fr );
                       <.htfcss from lg.>
    <.rewind lg file.> <.font=(...) from lg.>
    <.rewind lg file.> <.Font-css-base: ....>
    <.rewind lg file.> <.process Font-Size: ....>
    <.rewind lg file.> <.process Font(...).>
 } catch(Exception e){
    System.err.println( "--- OoFilter Error 2 --- " + e);
 }
-_-_-

<..rewind lg file..>
 in.close();
 fr  = new FileReader( fileName );
 in = new BufferedReader( fr );
-_-_-

<..htfcss from lg..>
 try{
    String key = "", body = "";
    while( (s=in.readLine()) != null ){
      if( s.startsWith("htfcss: ") ){
         s = s.substring(8);
         int idx = s.indexOf(’ ’);
         if( idx == 0 ){
            body += s;
         } else {
            <.map += (key, body).>
            if( idx == -1 ){
               key = s; body = "";
            } else {
               key = s.substring(0,idx);
               body = s.substring(idx);
    } }  }  }
    <.map += (key, body).>
 } catch(java.lang.NumberFormatException e){
    System.err.println( "--- OoFilter Error 3 --- Improper record: " + s);
 }
-_-_-

<..map += (key, body)..>
 body = body.trim();
 if( body.startsWith( "@media " ) ){
    body = body.substring(7).trim();
    if( body.startsWith("print ") ){
      body = body.substring(6).trim();
    } else { key = ""; }
 }
 if( !key.equals("") ){
    String [] property = body.split(";");
    for( int i=0; i<property.length; i++ ){
       if( !property[i].trim().equals("") ){
          int indx = property[i].indexOf(":");
          if( indx != -1 ){
             String name = property[i].substring(0,indx).trim();
             String value = (property[i]+’ ’).substring(indx+1).trim();
             if( !name.equals("") && !value.equals("") ){
                <.map[key] += (name,value).>
 }  }  }  }  }
-_-_-

<..map[key] += (name,value)..>
 if( map.containsKey(key) ){
    HashMap <String,String> entry = map.get(key);
    entry.put(name,value);
 }
 else
 {
    HashMap <String,String> entry = new HashMap <String,String>();
    entry.put(name,value);
    map.put(key,entry);
 }
-_-_-

<..load font vars..>
 HashMap <String,HashMap <String,String>> map
        = new HashMap<String,HashMap <String,String>>();
-_-_-

<..Font-css-base: .....>
 try{
    while( (s=in.readLine()) != null ){
      if( s.startsWith("Font_css_base: ") ){
        int idx = s.indexOf("Font_css_mag: ");
        if( idx != -1 ){
           String [] pattern = s.substring(15,idx).trim().split("%s");
           if( pattern.length == 3 ){ font_css_base = pattern; }
           pattern = (s+’ ’).substring(idx).trim().split("%s");
           if( pattern.length == 2 ){ font_css_mag = pattern; }
    } } }
 } catch(Exception e){
    System.err.println( "--- OoFilter Error 4 --- Improper record: " + s);
 }
-_-_-

<..process Font-Size: .....>
 try{
    while( (s=in.readLine()) != null ){
      if( s.startsWith("Font_Size:") ){
         base_font_size = Integer.parseInt( s.substring(10).trim() );
    } }
 } catch(java.lang.NumberFormatException e){
    System.err.println( "--- OoFilter Error 5 --- Improper record: " + s);
 }
-_-_-

<..process Font(...)..>
 try{
    while( (s=in.readLine()) != null ){
      if( s.startsWith("Font(") ){
         String [] match = s.split("\"");
         match[1] = match[1].trim();
         match[2] = match[3].trim();
         match[3] = match[5].trim();
         match[4] = match[7].trim();
         <.get font size.>
         <.get font style.>
    } }
 } catch(Exception e){
    System.err.println( "--- OoFilter Error 6 --- Improper record: " + s);
 }
-_-_-

<..get font style..>
 HashMap <String,String> entry = map.get(match[1]);
 if( (entry != null) || (second < 98) || (second > 102) ){
    String styleName = font_css_base[0] + match[1] +
                       font_css_base[1] + match[2] +
                       font_css_base[2];
    if( !match[4].equals("100") ){
       styleName += font_css_mag[0] + match[4] + font_css_mag[1];
    }
    <.attr[style:style] := ....>
    super.startElement(null, "style:style", "style:style", attr);
    <.attr[style:text-properties] := ....>
    super.startElement(null, "style:text-properties",
                                  "style:text-properties", attr);
    super.endElement(null, "style:text-properties",
                                        "style:text-properties");
    super.endElement(null, "style:style", "style:style");
 }
-_-_-

<..attr[style:style] := .....>
 org.xml.sax.helpers.AttributesImpl attr =
                       new org.xml.sax.helpers.AttributesImpl();
 attr.addAttribute("", "style:name", "style:name", "String", styleName);
 attr.addAttribute("", "style:family", "style:family", "String", "text");
-_-_-

<..attr[style:text-properties] := .....>
 attr = new org.xml.sax.helpers.AttributesImpl();
 if( entry != null ){
    Object [] name = entry.keySet().toArray();
    for(int i=0; i < name.length; i++){
       String value = entry.get(name[i]);
       attr.addAttribute("", "fo:" + (String) name[i],
                             "fo:" + (String) name[i],
                                                 "String", value);
 }  }
 if( (second < 98) || (second > 102) ){
    attr.addAttribute("", "fo:font-size", "fo:font-size",
                                   "String", (second / 10.0) + "pt");
 }
-_-_-

<..load font vars..>+
 String [] font_css_base = {"" , "-", ""};
 String [] font_css_mag = {"x-x-", ""};
-_-_-

<..print font style css..>
 (IGNORED) fprintf(css_file,
    (Font_css_base == NULL)? ".%s-%s" : Font_css_base,
    match[1], match[2]);
 if( !eq_str(match[4],"100") ){
    (IGNORED) fprintf(css_file,
    (Font_css_mag == NULL)? "x-x-%s" : Font_css_mag,
    match[4]);
 }
 (IGNORED) fprintf(css_file, "{");
 if( (second < 98) || (second > 102) ){
    (IGNORED) fprintf(css_file, "font-size:%d%c;", second, ’%’);
 }
 if( font_sty  ) {
    (IGNORED) fprintf(css_file, font_sty->body);
 }
 (IGNORED) fprintf(css_file, "}\n");
-_-_-

<..get font size..>
 {
    if( match[3].replaceAll("[0-9]","").equals("") ){
       second =   (int)
               (  Integer.parseInt( match[3] )
                * Long.parseLong( match[4] )
                / base_font_size
               );
       while( second > 700 ){  second /= 10; }
    } else { second = 100; }
    <.inspect font-size argument.>
 }
-_-_-

The following case handles cases like that of ‘Font("ecti","1095","10","100")’, where base_font_size is 11.

<..inspect font-size argument..>
 if(  (int) (  Double.parseDouble(match[2])
             / Long.parseLong(match[4])
             + 0.5
            )
       == base_font_size
 ){
    second = 100;
 };
-_-_-

<..load font vars..>+
 int base_font_size = 10;
 int second;
-_-_-

<..OoFilter imports..>
 import java.util.*;
 import org.xml.sax.helpers.*;
 import org.xml.sax.*;
 import java.io.PrintWriter;
 import java.io.BufferedReader;
 import java.io.FileReader;
-_-_-