jdk/src/java.desktop/share/native/libfontmanager/layout/IndicRearrangementProcessor2.cpp
changeset 33299 78f5508cde89
parent 31692 6f9d9bd603ce
child 35291 924c479304a5
equal deleted inserted replaced
33298:617fcb4b52f8 33299:78f5508cde89
    72        success = LE_INDEX_OUT_OF_BOUNDS_ERROR;
    72        success = LE_INDEX_OUT_OF_BOUNDS_ERROR;
    73        return 0;
    73        return 0;
    74     }
    74     }
    75 
    75 
    76     if (flags & irfMarkFirst) {
    76     if (flags & irfMarkFirst) {
    77         firstGlyph = currGlyph;
    77         firstGlyph = (le_uint32)currGlyph;
    78     }
    78     }
    79 
    79 
    80     if (flags & irfMarkLast) {
    80     if (flags & irfMarkLast) {
    81         lastGlyph = currGlyph;
    81         lastGlyph = (le_uint32)currGlyph;
    82     }
    82     }
    83 
    83 
    84     doRearrangementAction(glyphStorage, (IndicRearrangementVerb) (flags & irfVerbMask));
    84     doRearrangementAction(glyphStorage, (IndicRearrangementVerb) (flags & irfVerbMask), success);
    85 
    85 
    86     if (!(flags & irfDontAdvance)) {
    86     if (!(flags & irfDontAdvance)) {
    87         currGlyph += dir;
    87         currGlyph += dir;
    88     }
    88     }
    89 
    89 
    92 
    92 
    93 void IndicRearrangementProcessor2::endStateTable()
    93 void IndicRearrangementProcessor2::endStateTable()
    94 {
    94 {
    95 }
    95 }
    96 
    96 
    97 void IndicRearrangementProcessor2::doRearrangementAction(LEGlyphStorage &glyphStorage, IndicRearrangementVerb verb) const
    97 void IndicRearrangementProcessor2::doRearrangementAction(LEGlyphStorage &glyphStorage, IndicRearrangementVerb verb, LEErrorCode &success) const
    98 {
    98 {
    99     LEGlyphID a, b, c, d;
    99     LEGlyphID a, b, c, d;
   100     le_int32 ia, ib, ic, id, ix, x;
   100     le_int32 ia, ib, ic, id, ix, x;
   101     LEErrorCode success = LE_NO_ERROR;
   101 
       
   102     if (LE_FAILURE(success)) return;
       
   103 
       
   104     if (verb == irvNoAction) {
       
   105         return;
       
   106     }
       
   107     if (firstGlyph > lastGlyph) {
       
   108         success = LE_INDEX_OUT_OF_BOUNDS_ERROR;
       
   109         return;
       
   110     }
   102 
   111 
   103     switch(verb)
   112     switch(verb)
   104     {
   113     {
   105     case irvNoAction:
       
   106         break;
       
   107 
       
   108     case irvxA:
   114     case irvxA:
       
   115         if (firstGlyph == lastGlyph) break;
       
   116         if (firstGlyph + 1 < firstGlyph) {
       
   117             success = LE_INDEX_OUT_OF_BOUNDS_ERROR;
       
   118         break;
       
   119         }
   109         a = glyphStorage[firstGlyph];
   120         a = glyphStorage[firstGlyph];
   110         ia = glyphStorage.getCharIndex(firstGlyph, success);
   121         ia = glyphStorage.getCharIndex(firstGlyph, success);
   111         x = firstGlyph + 1;
   122         x = firstGlyph + 1;
   112 
   123 
   113         while (x <= lastGlyph) {
   124         while (x <= lastGlyph) {
   120         glyphStorage[lastGlyph] = a;
   131         glyphStorage[lastGlyph] = a;
   121         glyphStorage.setCharIndex(lastGlyph, ia, success);
   132         glyphStorage.setCharIndex(lastGlyph, ia, success);
   122         break;
   133         break;
   123 
   134 
   124     case irvDx:
   135     case irvDx:
       
   136         if (firstGlyph == lastGlyph) break;
       
   137         if (lastGlyph - 1 > lastGlyph) {
       
   138             success = LE_INDEX_OUT_OF_BOUNDS_ERROR;
       
   139             break;
       
   140         }
   125         d = glyphStorage[lastGlyph];
   141         d = glyphStorage[lastGlyph];
   126         id = glyphStorage.getCharIndex(lastGlyph, success);
   142         id = glyphStorage.getCharIndex(lastGlyph, success);
   127         x = lastGlyph - 1;
   143         x = lastGlyph - 1;
   128 
   144 
   129         while (x >= firstGlyph) {
   145         while (x >= firstGlyph) {
   148         glyphStorage.setCharIndex(firstGlyph, id, success);
   164         glyphStorage.setCharIndex(firstGlyph, id, success);
   149         glyphStorage.setCharIndex(lastGlyph,  ia, success);
   165         glyphStorage.setCharIndex(lastGlyph,  ia, success);
   150         break;
   166         break;
   151 
   167 
   152     case irvxAB:
   168     case irvxAB:
       
   169         if ((firstGlyph + 2 < firstGlyph) ||
       
   170             (lastGlyph - firstGlyph < 1)) { // difference == 1 is a no-op, < 1 is an error.
       
   171             success = LE_INDEX_OUT_OF_BOUNDS_ERROR;
       
   172             break;
       
   173         }
   153         a = glyphStorage[firstGlyph];
   174         a = glyphStorage[firstGlyph];
   154         b = glyphStorage[firstGlyph + 1];
   175         b = glyphStorage[firstGlyph + 1];
   155         ia = glyphStorage.getCharIndex(firstGlyph, success);
   176         ia = glyphStorage.getCharIndex(firstGlyph, success);
   156         ib = glyphStorage.getCharIndex(firstGlyph + 1, success);
   177         ib = glyphStorage.getCharIndex(firstGlyph + 1, success);
   157         x = firstGlyph + 2;
   178         x = firstGlyph + 2;
   169         glyphStorage.setCharIndex(lastGlyph - 1, ia, success);
   190         glyphStorage.setCharIndex(lastGlyph - 1, ia, success);
   170         glyphStorage.setCharIndex(lastGlyph, ib, success);
   191         glyphStorage.setCharIndex(lastGlyph, ib, success);
   171         break;
   192         break;
   172 
   193 
   173     case irvxBA:
   194     case irvxBA:
       
   195         if ((firstGlyph + 2 < firstGlyph) ||
       
   196             (lastGlyph - firstGlyph < 1)) {
       
   197             success = LE_INDEX_OUT_OF_BOUNDS_ERROR;
       
   198             break;
       
   199         }
   174         a = glyphStorage[firstGlyph];
   200         a = glyphStorage[firstGlyph];
   175         b = glyphStorage[firstGlyph + 1];
   201         b = glyphStorage[firstGlyph + 1];
   176         ia = glyphStorage.getCharIndex(firstGlyph, success);
   202         ia = glyphStorage.getCharIndex(firstGlyph, success);
   177         ib = glyphStorage.getCharIndex(firstGlyph + 1, success);
   203         ib = glyphStorage.getCharIndex(firstGlyph + 1, success);
   178         x = firstGlyph + 2;
   204         x = firstGlyph + 2;
   190         glyphStorage.setCharIndex(lastGlyph - 1, ib, success);
   216         glyphStorage.setCharIndex(lastGlyph - 1, ib, success);
   191         glyphStorage.setCharIndex(lastGlyph, ia, success);
   217         glyphStorage.setCharIndex(lastGlyph, ia, success);
   192         break;
   218         break;
   193 
   219 
   194     case irvCDx:
   220     case irvCDx:
       
   221         if ((lastGlyph - 2 > lastGlyph) ||
       
   222             (lastGlyph - firstGlyph < 1)) {
       
   223             success = LE_INDEX_OUT_OF_BOUNDS_ERROR;
       
   224             break;
       
   225         }
   195         c = glyphStorage[lastGlyph - 1];
   226         c = glyphStorage[lastGlyph - 1];
   196         d = glyphStorage[lastGlyph];
   227         d = glyphStorage[lastGlyph];
   197         ic = glyphStorage.getCharIndex(lastGlyph - 1, success);
   228         ic = glyphStorage.getCharIndex(lastGlyph - 1, success);
   198         id = glyphStorage.getCharIndex(lastGlyph, success);
   229         id = glyphStorage.getCharIndex(lastGlyph, success);
   199         x = lastGlyph - 2;
   230         x = lastGlyph - 2;
   211         glyphStorage.setCharIndex(firstGlyph, ic, success);
   242         glyphStorage.setCharIndex(firstGlyph, ic, success);
   212         glyphStorage.setCharIndex(firstGlyph + 1, id, success);
   243         glyphStorage.setCharIndex(firstGlyph + 1, id, success);
   213         break;
   244         break;
   214 
   245 
   215     case irvDCx:
   246     case irvDCx:
       
   247         if ((lastGlyph - 2 > lastGlyph) ||
       
   248             (lastGlyph - firstGlyph < 1)) {
       
   249             success = LE_INDEX_OUT_OF_BOUNDS_ERROR;
       
   250             break;
       
   251         }
   216         c = glyphStorage[lastGlyph - 1];
   252         c = glyphStorage[lastGlyph - 1];
   217         d = glyphStorage[lastGlyph];
   253         d = glyphStorage[lastGlyph];
   218         ic = glyphStorage.getCharIndex(lastGlyph - 1, success);
   254         ic = glyphStorage.getCharIndex(lastGlyph - 1, success);
   219         id = glyphStorage.getCharIndex(lastGlyph, success);
   255         id = glyphStorage.getCharIndex(lastGlyph, success);
   220         x = lastGlyph - 2;
   256         x = lastGlyph - 2;
   232         glyphStorage.setCharIndex(firstGlyph, id, success);
   268         glyphStorage.setCharIndex(firstGlyph, id, success);
   233         glyphStorage.setCharIndex(firstGlyph + 1, ic, success);
   269         glyphStorage.setCharIndex(firstGlyph + 1, ic, success);
   234         break;
   270         break;
   235 
   271 
   236     case irvCDxA:
   272     case irvCDxA:
       
   273         if ((lastGlyph - 2 > lastGlyph) ||
       
   274             (lastGlyph - firstGlyph < 2)) {
       
   275             success = LE_INDEX_OUT_OF_BOUNDS_ERROR;
       
   276             break;
       
   277         }
   237         a = glyphStorage[firstGlyph];
   278         a = glyphStorage[firstGlyph];
   238         c = glyphStorage[lastGlyph - 1];
   279         c = glyphStorage[lastGlyph - 1];
   239         d = glyphStorage[lastGlyph];
   280         d = glyphStorage[lastGlyph];
   240         ia = glyphStorage.getCharIndex(firstGlyph, success);
   281         ia = glyphStorage.getCharIndex(firstGlyph, success);
   241         ic = glyphStorage.getCharIndex(lastGlyph - 1, success);
   282         ic = glyphStorage.getCharIndex(lastGlyph - 1, success);
   257         glyphStorage.setCharIndex(firstGlyph + 1, id, success);
   298         glyphStorage.setCharIndex(firstGlyph + 1, id, success);
   258         glyphStorage.setCharIndex(lastGlyph, ia, success);
   299         glyphStorage.setCharIndex(lastGlyph, ia, success);
   259         break;
   300         break;
   260 
   301 
   261     case irvDCxA:
   302     case irvDCxA:
       
   303         if ((lastGlyph - 2 > lastGlyph) ||
       
   304             (lastGlyph - firstGlyph < 2)) {
       
   305             success = LE_INDEX_OUT_OF_BOUNDS_ERROR;
       
   306             break;
       
   307         }
   262         a = glyphStorage[firstGlyph];
   308         a = glyphStorage[firstGlyph];
   263         c = glyphStorage[lastGlyph - 1];
   309         c = glyphStorage[lastGlyph - 1];
   264         d = glyphStorage[lastGlyph];
   310         d = glyphStorage[lastGlyph];
   265         ia = glyphStorage.getCharIndex(firstGlyph, success);
   311         ia = glyphStorage.getCharIndex(firstGlyph, success);
   266         ic = glyphStorage.getCharIndex(lastGlyph - 1, success);
   312         ic = glyphStorage.getCharIndex(lastGlyph - 1, success);
   282         glyphStorage.setCharIndex(firstGlyph + 1, ic, success);
   328         glyphStorage.setCharIndex(firstGlyph + 1, ic, success);
   283         glyphStorage.setCharIndex(lastGlyph, ia, success);
   329         glyphStorage.setCharIndex(lastGlyph, ia, success);
   284         break;
   330         break;
   285 
   331 
   286     case irvDxAB:
   332     case irvDxAB:
       
   333         if ((firstGlyph + 2 < firstGlyph) ||
       
   334             (lastGlyph - firstGlyph < 2)) {
       
   335             success = LE_INDEX_OUT_OF_BOUNDS_ERROR;
       
   336             break;
       
   337         }
   287         a = glyphStorage[firstGlyph];
   338         a = glyphStorage[firstGlyph];
   288         b = glyphStorage[firstGlyph + 1];
   339         b = glyphStorage[firstGlyph + 1];
   289         d = glyphStorage[lastGlyph];
   340         d = glyphStorage[lastGlyph];
   290         ia = glyphStorage.getCharIndex(firstGlyph, success);
   341         ia = glyphStorage.getCharIndex(firstGlyph, success);
   291         ib = glyphStorage.getCharIndex(firstGlyph + 1, success);
   342         ib = glyphStorage.getCharIndex(firstGlyph + 1, success);
   307         glyphStorage.setCharIndex(lastGlyph - 1, ia, success);
   358         glyphStorage.setCharIndex(lastGlyph - 1, ia, success);
   308         glyphStorage.setCharIndex(lastGlyph, ib, success);
   359         glyphStorage.setCharIndex(lastGlyph, ib, success);
   309         break;
   360         break;
   310 
   361 
   311     case irvDxBA:
   362     case irvDxBA:
       
   363         if ((firstGlyph + 2 < firstGlyph) ||
       
   364             (lastGlyph - firstGlyph < 2)) {
       
   365             success = LE_INDEX_OUT_OF_BOUNDS_ERROR;
       
   366             break;
       
   367         }
   312         a = glyphStorage[firstGlyph];
   368         a = glyphStorage[firstGlyph];
   313         b = glyphStorage[firstGlyph + 1];
   369         b = glyphStorage[firstGlyph + 1];
   314         d = glyphStorage[lastGlyph];
   370         d = glyphStorage[lastGlyph];
   315         ia = glyphStorage.getCharIndex(firstGlyph, success);
   371         ia = glyphStorage.getCharIndex(firstGlyph, success);
   316         ib = glyphStorage.getCharIndex(firstGlyph + 1, success);
   372         ib = glyphStorage.getCharIndex(firstGlyph + 1, success);
   332         glyphStorage.setCharIndex(lastGlyph - 1, ib, success);
   388         glyphStorage.setCharIndex(lastGlyph - 1, ib, success);
   333         glyphStorage.setCharIndex(lastGlyph, ia, success);
   389         glyphStorage.setCharIndex(lastGlyph, ia, success);
   334         break;
   390         break;
   335 
   391 
   336     case irvCDxAB:
   392     case irvCDxAB:
       
   393         if (lastGlyph - firstGlyph < 3) {
       
   394             success = LE_INDEX_OUT_OF_BOUNDS_ERROR;
       
   395             break;
       
   396         }
   337         a = glyphStorage[firstGlyph];
   397         a = glyphStorage[firstGlyph];
   338         b = glyphStorage[firstGlyph + 1];
   398         b = glyphStorage[firstGlyph + 1];
   339 
   399 
   340         glyphStorage[firstGlyph] = glyphStorage[lastGlyph - 1];
   400         glyphStorage[firstGlyph] = glyphStorage[lastGlyph - 1];
   341         glyphStorage[firstGlyph + 1] = glyphStorage[lastGlyph];
   401         glyphStorage[firstGlyph + 1] = glyphStorage[lastGlyph];
   354         glyphStorage.setCharIndex(lastGlyph - 1, ia, success);
   414         glyphStorage.setCharIndex(lastGlyph - 1, ia, success);
   355         glyphStorage.setCharIndex(lastGlyph, ib, success);
   415         glyphStorage.setCharIndex(lastGlyph, ib, success);
   356         break;
   416         break;
   357 
   417 
   358     case irvCDxBA:
   418     case irvCDxBA:
       
   419         if (lastGlyph - firstGlyph < 3) {
       
   420             success = LE_INDEX_OUT_OF_BOUNDS_ERROR;
       
   421             break;
       
   422         }
   359         a = glyphStorage[firstGlyph];
   423         a = glyphStorage[firstGlyph];
   360         b = glyphStorage[firstGlyph + 1];
   424         b = glyphStorage[firstGlyph + 1];
   361 
   425 
   362         glyphStorage[firstGlyph] = glyphStorage[lastGlyph - 1];
   426         glyphStorage[firstGlyph] = glyphStorage[lastGlyph - 1];
   363         glyphStorage[firstGlyph + 1] = glyphStorage[lastGlyph];
   427         glyphStorage[firstGlyph + 1] = glyphStorage[lastGlyph];
   376         glyphStorage.setCharIndex(lastGlyph - 1, ib, success);
   440         glyphStorage.setCharIndex(lastGlyph - 1, ib, success);
   377         glyphStorage.setCharIndex(lastGlyph, ia, success);
   441         glyphStorage.setCharIndex(lastGlyph, ia, success);
   378         break;
   442         break;
   379 
   443 
   380     case irvDCxAB:
   444     case irvDCxAB:
       
   445         if (lastGlyph - firstGlyph < 3) {
       
   446             success = LE_INDEX_OUT_OF_BOUNDS_ERROR;
       
   447             break;
       
   448         }
   381         a = glyphStorage[firstGlyph];
   449         a = glyphStorage[firstGlyph];
   382         b = glyphStorage[firstGlyph + 1];
   450         b = glyphStorage[firstGlyph + 1];
   383 
   451 
   384         glyphStorage[firstGlyph] = glyphStorage[lastGlyph];
   452         glyphStorage[firstGlyph] = glyphStorage[lastGlyph];
   385         glyphStorage[firstGlyph + 1] = glyphStorage[lastGlyph - 1];
   453         glyphStorage[firstGlyph + 1] = glyphStorage[lastGlyph - 1];
   398         glyphStorage.setCharIndex(lastGlyph - 1, ia, success);
   466         glyphStorage.setCharIndex(lastGlyph - 1, ia, success);
   399         glyphStorage.setCharIndex(lastGlyph, ib, success);
   467         glyphStorage.setCharIndex(lastGlyph, ib, success);
   400         break;
   468         break;
   401 
   469 
   402     case irvDCxBA:
   470     case irvDCxBA:
       
   471         if (lastGlyph - firstGlyph < 3) {
       
   472             success = LE_INDEX_OUT_OF_BOUNDS_ERROR;
       
   473             break;
       
   474         }
   403         a = glyphStorage[firstGlyph];
   475         a = glyphStorage[firstGlyph];
   404         b = glyphStorage[firstGlyph + 1];
   476         b = glyphStorage[firstGlyph + 1];
   405 
   477 
   406         glyphStorage[firstGlyph] = glyphStorage[lastGlyph];
   478         glyphStorage[firstGlyph] = glyphStorage[lastGlyph];
   407         glyphStorage[firstGlyph + 1] = glyphStorage[lastGlyph - 1];
   479         glyphStorage[firstGlyph + 1] = glyphStorage[lastGlyph - 1];