Home | History | Annotate | Download | only in layout
      1 //  2016 and later: Unicode, Inc. and others.
      2 // License & terms of use: http://www.unicode.org/copyright.html#License
      3 /*
      4  *******************************************************************************
      5  * Copyright (C) 1998-2015, International Business Machines Corporation and
      6  * others. All Rights Reserved.
      7  *******************************************************************************
      8  */
      9 package com.ibm.icu.dev.tool.layout;
     10 
     11 import com.ibm.icu.lang.UScript;
     12 
     13 public class ScriptTagModuleWriter extends ScriptModuleWriter
     14 {
     15     public ScriptTagModuleWriter(ScriptData theScriptData, LanguageData theLanguageData)
     16     {
     17         super(theScriptData, theLanguageData);
     18     }
     19 
     20     private void writeTagValueHeader(TagValueData data, String kind)
     21     {
     22         int min = data.getMinValue();
     23         int max = data.getMaxValue();
     24 
     25         for (int value = min; value <= max; value += 1) {
     26             output.print("const LETag ");
     27             output.print(data.getTagLabel(value));
     28             output.print(kind);
     29             output.print("Tag = ");
     30             output.print(data.makeTag(value));
     31             output.print("; /* '");
     32             output.print(data.getTag(value));
     33             output.print("' (");
     34             output.print(data.getName(value));
     35             output.println(") */");
     36             if(kind.equals("Script")) {
     37                 switch(value) {
     38                 case UScript.BENGALI:
     39                     output.println("const LETag bng2ScriptTag = 0x626E6732; /* 'bng2' (BENGALI v.2) (manually added) */");
     40                     break;
     41                 case UScript.DEVANAGARI:
     42                     output.println("const LETag dev2ScriptTag = 0x64657632; /* 'dev2' (DEVANAGARI v.2) (manually added) */");
     43                     break;
     44                 case UScript.GUJARATI:
     45                     output.println("const LETag gjr2ScriptTag = 0x676A7232; /* 'gjr2' (GUJARATI v.2) (manually added) */");
     46                     break;
     47                 case UScript.GURMUKHI:
     48                     output.println("const LETag gur2ScriptTag = 0x67757232; /* 'gur2' (GURMUKHI v.2) (manually added) */");
     49                     break;
     50                 case UScript.KANNADA:
     51                     output.println("const LETag knd2ScriptTag = 0x6B6E6432; /* 'knd2' (KANNADA v.2) (manually added) */");
     52                     break;
     53                 case UScript.MALAYALAM:
     54                     output.println("const LETag mlm2ScriptTag = 0x6D6C6D32; /* 'mlm2' (MALAYALAM v.2) (manually added) */");
     55                     break;
     56                 case UScript.ORIYA:
     57                     output.println("const LETag ory2ScriptTag = 0x6F727932; /* 'ory2' (ORIYA v.2) (manually added) */");
     58                     break;
     59                 case UScript.TAMIL:
     60                     output.println("const LETag tml2ScriptTag = 0x746D6C32; /* 'tml2' (TAMIL v.2) (manually added) */");
     61                     break;
     62                 case UScript.TELUGU:
     63                     output.println("const LETag tel2ScriptTag = 0x74656C32; /* 'tel2' (TELUGU v.2) (manually added) */");
     64                     break;
     65                 default:
     66                     break;
     67                 }
     68             }
     69         }
     70     }
     71 
     72     public void writeHeaderFile(String fileName)
     73     {
     74         openFile(fileName);
     75         writeHeader("__SCRIPTANDLANGUAGES_H", hIncludes, hPreamble);
     76 
     77         writeTagValueHeader(scriptData, "Script");
     78 
     79         output.println(hScriptPostamble);
     80 
     81         writeTagValueHeader(languageData, "Language");
     82 
     83         output.println(hPostamble);
     84         closeFile();
     85     }
     86 
     87     private void writeTagValueCPP(TagValueData data, String kind)
     88     {
     89         int min = data.getMinValue();
     90         int max = data.getMaxValue();
     91 
     92         for (int value = min; value <= max; value += 1) {
     93             output.print("    ");
     94             output.print(data.getTagLabel(value));
     95             output.print(kind);
     96             output.print("Tag");
     97             output.print((value == max? " " : ","));
     98             output.print(" /* '");
     99             output.print(data.getTag(value));
    100             output.print("' (");
    101             output.print(data.getName(value));
    102             output.println(") */");
    103         }
    104     }
    105 
    106     public void writeCPPFile(String fileName)
    107     {
    108         openFile(fileName);
    109         writeHeader(null, cppIncludes);
    110         output.println(cppPreamble);
    111 
    112         writeTagValueCPP(scriptData, "Script");
    113 
    114         output.println(cppScriptPostamble);
    115 
    116         writeTagValueCPP(languageData, "Language");
    117 
    118         output.println(cppPostamble);
    119 
    120         writeTrailer();
    121         closeFile();
    122     }
    123 
    124     public void writeScriptTags(String fileName)
    125     {
    126         writeHeaderFile(fileName + ".h");
    127         writeCPPFile(fileName + ".cpp");
    128     }
    129 
    130     private static final String[] hIncludes = {"LETypes.h"};
    131 
    132     private static final String hPreamble =
    133     "/**\n" +
    134     " * \\file\n" +
    135     " * \\internal\n" +
    136     " */\n" +
    137     "\n";
    138 
    139     private static final String hScriptPostamble =
    140     "\n" +
    141     "const LETag nullScriptTag = 0x00000000; /* ''     (NULL) */\n" +
    142     "\n";
    143 
    144     private static final String hPostamble =
    145     "\n" +
    146     "\n" +
    147     "U_NAMESPACE_END\n" +
    148     "#endif";
    149 
    150     private static final String[] cppIncludes =
    151         {"LETypes.h", "ScriptAndLanguageTags.h", "OpenTypeLayoutEngine.h"};
    152 
    153     private static final String cppPreamble =
    154     "const LETag OpenTypeLayoutEngine::scriptTags[] = {";
    155 
    156     private static final String cppScriptPostamble =
    157     "};\n" +
    158     "\n" +
    159     "const LETag OpenTypeLayoutEngine::languageTags[] = {";
    160 
    161     private static final String cppPostamble =
    162     "};\n";
    163 }