347 (*env)->GetDoubleArrayRegion(env, matrix, 0, 4, dmat); 348 ptsz = euclidianDistance(dmat[2], dmat[3]); //i.e. y-size 349 if (ptsz < 1.0) { 350 //text can not be smaller than 1 point 351 ptsz = 1.0; 352 } 353 context->ptsz = (int)(ptsz * 64); 354 context->transform.xx = FloatToFTFixed((float)dmat[0]/ptsz); 355 context->transform.yx = -FloatToFTFixed((float)dmat[1]/ptsz); 356 context->transform.xy = -FloatToFTFixed((float)dmat[2]/ptsz); 357 context->transform.yy = FloatToFTFixed((float)dmat[3]/ptsz); 358 context->aaType = aa; 359 context->fmType = fm; 360 361 /* If using algorithmic styling, the base values are 362 * boldness = 1.0, italic = 0.0. 363 */ 364 context->doBold = (boldness != 1.0); 365 context->doItalize = (italic != 0); 366 367 return ptr_to_jlong(context); 368 } 369 370 static int setupFTContext(JNIEnv *env, 371 jobject font2D, 372 FTScalerInfo *scalerInfo, 373 FTScalerContext *context) { 374 int errCode = 0; 375 376 scalerInfo->env = env; 377 scalerInfo->font2D = font2D; 378 379 if (context != NULL) { 380 FT_Set_Transform(scalerInfo->face, &context->transform, NULL); 381 382 errCode = FT_Set_Char_Size(scalerInfo->face, 0, context->ptsz, 72, 72); 383 384 if (errCode == 0) { 385 errCode = FT_Activate_Size(scalerInfo->face->size); 386 } 668 GlyphInfo *glyphInfo; 669 int glyph_index; 670 int renderFlags = FT_LOAD_RENDER, target; 671 FT_GlyphSlot ftglyph; 672 673 FTScalerContext* context = 674 (FTScalerContext*) jlong_to_ptr(pScalerContext); 675 FTScalerInfo *scalerInfo = 676 (FTScalerInfo*) jlong_to_ptr(pScaler); 677 678 if (isNullScalerContext(context) || scalerInfo == NULL) { 679 return ptr_to_jlong(getNullGlyphImage()); 680 } 681 682 error = setupFTContext(env, font2D, scalerInfo, context); 683 if (error) { 684 invalidateJavaScaler(env, scaler, scalerInfo); 685 return ptr_to_jlong(getNullGlyphImage()); 686 } 687 688 /* if algorithmic styling is required then we do not request bitmap */ 689 if (context->doBold || context->doItalize) { 690 renderFlags = FT_LOAD_DEFAULT; 691 } 692 693 /* NB: in case of non identity transform 694 we might also prefer to disable transform before hinting, 695 and apply it explicitly after hinting is performed. 696 Or we can disable hinting. */ 697 698 /* select appropriate hinting mode */ 699 if (context->aaType == TEXT_AA_OFF) { 700 target = FT_LOAD_TARGET_MONO; 701 } else if (context->aaType == TEXT_AA_ON) { 702 target = FT_LOAD_TARGET_NORMAL; 703 } else if (context->aaType == TEXT_AA_LCD_HRGB || 704 context->aaType == TEXT_AA_LCD_HBGR) { 705 target = FT_LOAD_TARGET_LCD; 706 } else { 707 target = FT_LOAD_TARGET_LCD_V; 708 } 709 renderFlags |= target; 710 | 347 (*env)->GetDoubleArrayRegion(env, matrix, 0, 4, dmat); 348 ptsz = euclidianDistance(dmat[2], dmat[3]); //i.e. y-size 349 if (ptsz < 1.0) { 350 //text can not be smaller than 1 point 351 ptsz = 1.0; 352 } 353 context->ptsz = (int)(ptsz * 64); 354 context->transform.xx = FloatToFTFixed((float)dmat[0]/ptsz); 355 context->transform.yx = -FloatToFTFixed((float)dmat[1]/ptsz); 356 context->transform.xy = -FloatToFTFixed((float)dmat[2]/ptsz); 357 context->transform.yy = FloatToFTFixed((float)dmat[3]/ptsz); 358 context->aaType = aa; 359 context->fmType = fm; 360 361 /* If using algorithmic styling, the base values are 362 * boldness = 1.0, italic = 0.0. 363 */ 364 context->doBold = (boldness != 1.0); 365 context->doItalize = (italic != 0); 366 367 /* freetype is very keen to use embedded bitmaps, even if it knows 368 * there is a rotation or you asked for antialiasing. 369 * In the rendering path we will check useSBits and disable 370 * bitmaps unless it is set. And here we set it only if none 371 * of the conditions invalidate using it. 372 * Note that we allow embedded bitmaps for the LCD case. 373 */ 374 if ((aa != TEXT_AA_ON) && (fm != TEXT_FM_ON) && 375 !context->doBold && !context->doItalize && 376 (context->transform.yx == 0) && (context->transform.xy == 0)) 377 { 378 context->useSbits = 1; 379 } 380 return ptr_to_jlong(context); 381 } 382 383 static int setupFTContext(JNIEnv *env, 384 jobject font2D, 385 FTScalerInfo *scalerInfo, 386 FTScalerContext *context) { 387 int errCode = 0; 388 389 scalerInfo->env = env; 390 scalerInfo->font2D = font2D; 391 392 if (context != NULL) { 393 FT_Set_Transform(scalerInfo->face, &context->transform, NULL); 394 395 errCode = FT_Set_Char_Size(scalerInfo->face, 0, context->ptsz, 72, 72); 396 397 if (errCode == 0) { 398 errCode = FT_Activate_Size(scalerInfo->face->size); 399 } 681 GlyphInfo *glyphInfo; 682 int glyph_index; 683 int renderFlags = FT_LOAD_RENDER, target; 684 FT_GlyphSlot ftglyph; 685 686 FTScalerContext* context = 687 (FTScalerContext*) jlong_to_ptr(pScalerContext); 688 FTScalerInfo *scalerInfo = 689 (FTScalerInfo*) jlong_to_ptr(pScaler); 690 691 if (isNullScalerContext(context) || scalerInfo == NULL) { 692 return ptr_to_jlong(getNullGlyphImage()); 693 } 694 695 error = setupFTContext(env, font2D, scalerInfo, context); 696 if (error) { 697 invalidateJavaScaler(env, scaler, scalerInfo); 698 return ptr_to_jlong(getNullGlyphImage()); 699 } 700 701 if (!context->useSbits) { 702 renderFlags |= FT_LOAD_NO_BITMAP; 703 } 704 705 /* NB: in case of non identity transform 706 we might also prefer to disable transform before hinting, 707 and apply it explicitly after hinting is performed. 708 Or we can disable hinting. */ 709 710 /* select appropriate hinting mode */ 711 if (context->aaType == TEXT_AA_OFF) { 712 target = FT_LOAD_TARGET_MONO; 713 } else if (context->aaType == TEXT_AA_ON) { 714 target = FT_LOAD_TARGET_NORMAL; 715 } else if (context->aaType == TEXT_AA_LCD_HRGB || 716 context->aaType == TEXT_AA_LCD_HBGR) { 717 target = FT_LOAD_TARGET_LCD; 718 } else { 719 target = FT_LOAD_TARGET_LCD_V; 720 } 721 renderFlags |= target; 722 |