< prev index next >

src/java.desktop/share/native/libfontmanager/HBShaper.c

Print this page




 261                            pScaler, pNativeFont, matrix, aat);
 262      if (!jdkFontInfo) {
 263         return JNI_FALSE;
 264      }
 265      jdkFontInfo->env = env; // this is valid only for the life of this JNI call.
 266      jdkFontInfo->font2D = font2D;
 267      jdkFontInfo->fontStrike = fontStrike;
 268 
 269      hbfont = hb_jdk_font_create(jdkFontInfo, NULL);
 270 
 271      buffer = hb_buffer_create();
 272      hb_buffer_set_script(buffer, getHBScriptCode(script));
 273      hb_buffer_set_language(buffer,
 274                             hb_ot_tag_to_language(HB_OT_TAG_DEFAULT_LANGUAGE));
 275      if ((flags & TYPO_RTL) != 0) {
 276          direction = HB_DIRECTION_RTL;
 277      }
 278      hb_buffer_set_direction(buffer, direction);
 279 
 280      chars = (*env)->GetCharArrayElements(env, text, NULL);






 281      len = (*env)->GetArrayLength(env, text);
 282 
 283      hb_buffer_add_utf16(buffer, chars, len, offset, limit-offset);
 284 
 285      hb_shape_full(hbfont, buffer, features, featureCount, 0);
 286      glyphCount = hb_buffer_get_length(buffer);
 287      glyphInfo = hb_buffer_get_glyph_infos(buffer, 0);
 288      glyphPos = hb_buffer_get_glyph_positions(buffer, &buflen);
 289      for (i = 0; i < glyphCount; i++) {
 290          int index = glyphInfo[i].codepoint;
 291          int xadv = (glyphPos[i].x_advance);
 292          int yadv = (glyphPos[i].y_advance);
 293      }
 294      // On "input" HB assigns a cluster index to each character in UTF-16.
 295      // On output where a sequence of characters have been mapped to
 296      // a glyph they are all mapped to the cluster index of the first character.
 297      // The next cluster index will be that of the first character in the
 298      // next cluster. So cluster indexes may 'skip' on output.
 299      // This can also happen if there are supplementary code-points
 300      // such that two UTF-16 characters are needed to make one codepoint.
 301      // In RTL text you need to count down.
 302      // So the following code tries to build the reverse map as expected
 303      // by calling code.
 304 
 305      storeGVData(env, gvdata, slot, baseIndex, startPt,
 306                  glyphCount, glyphInfo, glyphPos, direction);
 307 
 308      hb_buffer_destroy (buffer);
 309      hb_font_destroy(hbfont);
 310      free((void*)jdkFontInfo);
 311      if (features != NULL) free(features);

 312 
 313      return JNI_TRUE;
 314 }
 315 


 261                            pScaler, pNativeFont, matrix, aat);
 262      if (!jdkFontInfo) {
 263         return JNI_FALSE;
 264      }
 265      jdkFontInfo->env = env; // this is valid only for the life of this JNI call.
 266      jdkFontInfo->font2D = font2D;
 267      jdkFontInfo->fontStrike = fontStrike;
 268 
 269      hbfont = hb_jdk_font_create(jdkFontInfo, NULL);
 270 
 271      buffer = hb_buffer_create();
 272      hb_buffer_set_script(buffer, getHBScriptCode(script));
 273      hb_buffer_set_language(buffer,
 274                             hb_ot_tag_to_language(HB_OT_TAG_DEFAULT_LANGUAGE));
 275      if ((flags & TYPO_RTL) != 0) {
 276          direction = HB_DIRECTION_RTL;
 277      }
 278      hb_buffer_set_direction(buffer, direction);
 279 
 280      chars = (*env)->GetCharArrayElements(env, text, NULL);
 281      if ((*env)->ExceptionCheck(env)) {
 282          hb_buffer_destroy(buffer);
 283          hb_font_destroy(hbfont);
 284          free((void*)jdkFontInfo);
 285          return JNI_FALSE;
 286      }
 287      len = (*env)->GetArrayLength(env, text);
 288 
 289      hb_buffer_add_utf16(buffer, chars, len, offset, limit-offset);
 290 
 291      hb_shape_full(hbfont, buffer, features, featureCount, 0);
 292      glyphCount = hb_buffer_get_length(buffer);
 293      glyphInfo = hb_buffer_get_glyph_infos(buffer, 0);
 294      glyphPos = hb_buffer_get_glyph_positions(buffer, &buflen);
 295      for (i = 0; i < glyphCount; i++) {
 296          int index = glyphInfo[i].codepoint;
 297          int xadv = (glyphPos[i].x_advance);
 298          int yadv = (glyphPos[i].y_advance);
 299      }
 300      // On "input" HB assigns a cluster index to each character in UTF-16.
 301      // On output where a sequence of characters have been mapped to
 302      // a glyph they are all mapped to the cluster index of the first character.
 303      // The next cluster index will be that of the first character in the
 304      // next cluster. So cluster indexes may 'skip' on output.
 305      // This can also happen if there are supplementary code-points
 306      // such that two UTF-16 characters are needed to make one codepoint.
 307      // In RTL text you need to count down.
 308      // So the following code tries to build the reverse map as expected
 309      // by calling code.
 310 
 311      storeGVData(env, gvdata, slot, baseIndex, startPt,
 312                  glyphCount, glyphInfo, glyphPos, direction);
 313 
 314      hb_buffer_destroy (buffer);
 315      hb_font_destroy(hbfont);
 316      free((void*)jdkFontInfo);
 317      if (features != NULL) free(features);
 318      (*env)->ReleaseCharArrayElements(env, text, chars, JNI_ABORT);
 319 
 320      return JNI_TRUE;
 321 }
 322 
< prev index next >