src/macosx/native/sun/awt/CTextPipe.m

Print this page




  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 //  Native side of the Quartz text pipe, paints on Quartz Surface Datas.
  27 //  Interesting Docs : /Developer/Documentation/Cocoa/TasksAndConcepts/ProgrammingTopics/FontHandling/FontHandling.html
  28 
  29 #import "sun_awt_SunHints.h"
  30 #import "sun_lwawt_macosx_CTextPipe.h"
  31 #import "sun_java2d_OSXSurfaceData.h"
  32 
  33 #import <JavaNativeFoundation/JavaNativeFoundation.h>
  34 
  35 #import "CoreTextSupport.h"
  36 #import "QuartzSurfaceData.h"
  37 #include "AWTStrike.h"
  38 




  39 
  40 static const CGAffineTransform sInverseTX = { 1, 0, 0, -1, 0, 0 };
  41 
  42 
  43 #pragma mark --- CoreText Support ---
  44 
  45 
  46 // Translates a Unicode into a CGGlyph/CTFontRef pair
  47 // Returns the substituted font, and places the appropriate glyph into "glyphRef"
  48 CTFontRef JavaCT_CopyCTFallbackFontAndGlyphForUnicode
  49 (const AWTFont *font, const UTF16Char *charRef, CGGlyph *glyphRef, int count) {
  50     CTFontRef fallback = JRSFontCreateFallbackFontForCharacters((CTFontRef)font->fFont, charRef, count);
  51     if (fallback == NULL)
  52     {
  53         // use the original font if we somehow got duped into trying to fallback something we can't
  54         fallback = (CTFontRef)font->fFont;
  55         CFRetain(fallback);
  56     }
  57 
  58     CTFontGetGlyphsForCharacters(fallback, charRef, glyphRef, count);


 471     }
 472 
 473     if (length < MAX_STACK_ALLOC_GLYPH_BUFFER_SIZE)
 474     {
 475         // if we are small enough, fit everything onto the stack
 476         CGGlyph glyphs[length];
 477         int uniChars[length];
 478         CGSize advances[length];
 479         doDrawGlyphsPipe_fillGlyphAndAdvanceBuffers(env, qsdo, strike, gVector, glyphs, uniChars, advances, length, glyphsArray);
 480     }
 481     else
 482     {
 483         // otherwise, we should malloc and free buffers for this large run
 484         CGGlyph *glyphs = (CGGlyph *)malloc(sizeof(CGGlyph) * length);
 485         int *uniChars = (int *)malloc(sizeof(int) * length);
 486         CGSize *advances = (CGSize *)malloc(sizeof(CGSize) * length);
 487 
 488         if (glyphs == NULL || advances == NULL)
 489         {
 490             (*env)->DeleteLocalRef(env, glyphsArray);
 491             [NSException raise:NSMallocException format:@"%s-%s:%d", __FILE__, __FUNCTION__, __LINE__];
 492             return;
 493         }
 494 
 495         doDrawGlyphsPipe_fillGlyphAndAdvanceBuffers(env, qsdo, strike, gVector, glyphs, uniChars, advances, length, glyphsArray);
 496 
 497         free(glyphs);
 498         free(uniChars);
 499         free(advances);
 500     }
 501 
 502     (*env)->DeleteLocalRef(env, glyphsArray);
 503 }
 504 
 505 // Setup and save the state of the CGContext, and apply any java.awt.Font transforms to the context.
 506 static inline void doDrawGlyphsPipe_applyFontTransforms
 507 (JNIEnv *env, QuartzSDOps *qsdo, const AWTStrike *strike, jobject gVector, const jfloat x, const jfloat y)
 508 {
 509     CGContextRef cgRef = qsdo->cgRef;
 510     CGContextSetFontSize(cgRef, 1.0);
 511     CGContextSetFont(cgRef, strike->fAWTFont->fNativeCGFont);




  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 //  Native side of the Quartz text pipe, paints on Quartz Surface Datas.
  27 //  Interesting Docs : /Developer/Documentation/Cocoa/TasksAndConcepts/ProgrammingTopics/FontHandling/FontHandling.html
  28 
  29 #import "sun_awt_SunHints.h"
  30 #import "sun_lwawt_macosx_CTextPipe.h"
  31 #import "sun_java2d_OSXSurfaceData.h"
  32 
  33 #import <JavaNativeFoundation/JavaNativeFoundation.h>
  34 
  35 #import "CoreTextSupport.h"
  36 #import "QuartzSurfaceData.h"
  37 #include "AWTStrike.h"
  38 
  39 /* Use THIS_FILE when it is available. */
  40 #ifndef THIS_FILE
  41     #define THIS_FILE __FILE__
  42 #endif
  43 
  44 static const CGAffineTransform sInverseTX = { 1, 0, 0, -1, 0, 0 };
  45 
  46 
  47 #pragma mark --- CoreText Support ---
  48 
  49 
  50 // Translates a Unicode into a CGGlyph/CTFontRef pair
  51 // Returns the substituted font, and places the appropriate glyph into "glyphRef"
  52 CTFontRef JavaCT_CopyCTFallbackFontAndGlyphForUnicode
  53 (const AWTFont *font, const UTF16Char *charRef, CGGlyph *glyphRef, int count) {
  54     CTFontRef fallback = JRSFontCreateFallbackFontForCharacters((CTFontRef)font->fFont, charRef, count);
  55     if (fallback == NULL)
  56     {
  57         // use the original font if we somehow got duped into trying to fallback something we can't
  58         fallback = (CTFontRef)font->fFont;
  59         CFRetain(fallback);
  60     }
  61 
  62     CTFontGetGlyphsForCharacters(fallback, charRef, glyphRef, count);


 475     }
 476 
 477     if (length < MAX_STACK_ALLOC_GLYPH_BUFFER_SIZE)
 478     {
 479         // if we are small enough, fit everything onto the stack
 480         CGGlyph glyphs[length];
 481         int uniChars[length];
 482         CGSize advances[length];
 483         doDrawGlyphsPipe_fillGlyphAndAdvanceBuffers(env, qsdo, strike, gVector, glyphs, uniChars, advances, length, glyphsArray);
 484     }
 485     else
 486     {
 487         // otherwise, we should malloc and free buffers for this large run
 488         CGGlyph *glyphs = (CGGlyph *)malloc(sizeof(CGGlyph) * length);
 489         int *uniChars = (int *)malloc(sizeof(int) * length);
 490         CGSize *advances = (CGSize *)malloc(sizeof(CGSize) * length);
 491 
 492         if (glyphs == NULL || advances == NULL)
 493         {
 494             (*env)->DeleteLocalRef(env, glyphsArray);
 495             [NSException raise:NSMallocException format:@"%s-%s:%d", THIS_FILE, __FUNCTION__, __LINE__];
 496             return;
 497         }
 498 
 499         doDrawGlyphsPipe_fillGlyphAndAdvanceBuffers(env, qsdo, strike, gVector, glyphs, uniChars, advances, length, glyphsArray);
 500 
 501         free(glyphs);
 502         free(uniChars);
 503         free(advances);
 504     }
 505 
 506     (*env)->DeleteLocalRef(env, glyphsArray);
 507 }
 508 
 509 // Setup and save the state of the CGContext, and apply any java.awt.Font transforms to the context.
 510 static inline void doDrawGlyphsPipe_applyFontTransforms
 511 (JNIEnv *env, QuartzSDOps *qsdo, const AWTStrike *strike, jobject gVector, const jfloat x, const jfloat y)
 512 {
 513     CGContextRef cgRef = qsdo->cgRef;
 514     CGContextSetFontSize(cgRef, 1.0);
 515     CGContextSetFont(cgRef, strike->fAWTFont->fNativeCGFont);