/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
// Native side of the Quartz text pipe, paints on Quartz Surface Datas.
// Interesting Docs : /Developer/Documentation/Cocoa/TasksAndConcepts/ProgrammingTopics/FontHandling/FontHandling.html
#import "sun_awt_SunHints.h"
#import "sun_lwawt_macosx_CTextPipe.h"
#import "sun_java2d_OSXSurfaceData.h"
#import "CoreTextSupport.h"
#import "QuartzSurfaceData.h"
#include "AWTStrike.h"
// Returns the substituted font, and places the appropriate glyph into "glyphRef"
CTFontRef fallback = JRSFontCreateFallbackFontForCharacters((CTFontRef)font->fFont, charRef, count);
{
// use the original font if we somehow got duped into trying to fallback something we can't
}
return fallback;
}
// Translates a Java glyph code int (might be a negative unicode value) into a CGGlyph/CTFontRef pair
// Returns the substituted font, and places the appropriate glyph into "glyph"
{
// negative glyph codes are really unicodes, which were placed there by the mapper
// to indicate we should use CoreText to substitute the character
if (glyphCode >= 0)
{
}
}
// Breakup a 32 bit unicode value into the component surrogate pairs
}
/*
* Callback for CoreText which uses the CoreTextProviderStruct to feed CT UniChars
* We only use it for one-off lines, and don't attempt to fragment our strings
*/
const UniChar *Java_CTProvider
{
// if we have a zero length string we can just return NULL for the string
// or if the index anything other than 0 we are not using core text
// correctly since we only have one run.
if (stringIndex != 0)
{
return NULL;
}
}
/*
* Gets a Dictionary filled with common details we want to use for CoreText when we are interacting
* with it from Java.
*/
{
return [NSDictionary dictionaryWithObjectsAndKeys:
useFractionalMetrics ? gZeroNumber : gOneNumber, @"CTIntegerMetrics", // force integer hack in CoreText to help with Java's integer assumptions
nil];
}
// Itterates though each glyph, and if a transform is present for that glyph, apply it to the CGContext, and strike the glyph.
// If there is no per-glyph transform, just strike the glyph. Advances must also be transformed on-the-spot as well.
(const QuartzSDOps *qsdo, const AWTStrike *strike, const BOOL useSubstituion, const int uniChars[], const CGGlyph glyphs[], CGSize advances[], const jint g_gvTXIndicesAsInts[], const jdouble g_gvTransformsAsDoubles[], const CFIndex length)
{
// get our baseline transform and font
/* Save and restore of graphics context is done before the iteration.
This seems to work using our test case (see bug ID 7158350) so we are restoring it at
NSUInteger i;
for (i = 0; i < length; i++)
{
// if we found a unichar instead of a glyph code, get the fallback font,
// find the glyph code for the fallback font, and set the font on the current context
if (uniChar != 0)
{
if (uniChar > 0xFFFF) {
fallback = JavaCT_CopyCTFallbackFontAndGlyphForUnicode(strike->fAWTFont, (const UTF16Char *)&charRef, (CGGlyph *)&glyphTmp, 2);
} else {
}
if (fallback) {
if (cgFallback) {
if (!saved) {
saved = true;
}
}
}
} else {
if (saved) {
saved = false;
}
}
// if we have per-glyph transformations
if (tin < 0)
{
}
else
{
0, 0);
CGPoint txOffset = { (CGFloat)g_gvTransformsAsDoubles[tin + 4], (CGFloat)g_gvTransformsAsDoubles[tin + 5] };
// apply the transform, strike the glyph, can change the transform back
// transform the measured advance for this strike
}
// move our next x,y
}
// reset the font on the context after striking a unicode with CoreText
}
// Using the Quartz Surface Data context, draw a hot-substituted character run
void JavaCT_DrawTextUsingQSD(JNIEnv *env, const QuartzSDOps *qsdo, const AWTStrike *strike, const jchar *chars, const jsize length)
{
if (ptSize != 0) {
}
/*
The calls below were used previously but for unknown reason did not
render using the right font (see bug 7183516) when attribString is not
initialized with font dictionary attributes. It seems that "options"
in CTTypesetterCreateWithAttributedStringAndOptions which contains the
font dictionary is ignored.
NSAttributedString *attribString = [[NSAttributedString alloc] initWithString:string];
CTTypesetterRef typeSetterRef = CTTypesetterCreateWithAttributedStringAndOptions((CFAttributedStringRef) attribString, (CFDictionaryRef) ctsDictionaryFor(nsFont, JRSFontStyleUsesFractionalMetrics(strike->fStyle)));
*/
CTTypesetterRef typeSetterRef = CTTypesetterCreateWithAttributedString((CFAttributedStringRef) attribString);
}
/*----------------------
DrawTextContext is the funnel for all of our CoreText drawing.
All three JNI apis call through this method.
----------------------*/
static void DrawTextContext
(JNIEnv *env, QuartzSDOps *qsdo, const AWTStrike *strike, const jchar *chars, const jsize length, const jdouble x, const jdouble y)
{
if (length == 0)
{
return;
}
{
return;
}
// we want to translate before we transform (scale or rotate) <rdar://4042541> (vm)
CGContextTranslateCTM(cgRef, x, y);
}
/*-----------------------------------
Glyph Vector Pipeline
doDrawGlyphs() has been separated into several pipelined functions to increase performance,
and improve accountability for JNI resources, malloc'd memory, and error handling.
Each stage of the pipeline is responsible for doing only one major thing, like allocating buffers,
aquiring transform arrays from JNI, filling buffers, or striking glyphs. All resources or memory
aquired at a given stage, must be released in that stage. Any error that occurs (like a failed malloc)
is to be handled in the stage it occurs in, and is to return immediatly after freeing it's resources.
-----------------------------------*/
// Checks the GlyphVector Java object for any transforms that were applied to individual characters. If none are present,
// strike the glyphs immediately in Core Graphics. Otherwise, obtain the arrays, and defer to above.
static inline void doDrawGlyphsPipe_checkForPerGlyphTransforms
(JNIEnv *env, QuartzSDOps *qsdo, const AWTStrike *strike, jobject gVector, BOOL useSubstituion, int *uniChars, CGGlyph *glyphs, CGSize *advances, size_t length)
{
// if we have no character substitution, and no per-glyph transformations - strike now!
static JNF_MEMBER_CACHE(jm_StandardGlyphVector_gti, jc_StandardGlyphVector, "gti", "Lsun/font/StandardGlyphVector$GlyphTransformInfo;");
if (gti == 0)
{
if (useSubstituion)
{
// quasi-simple case, substitution, but no per-glyph transforms
}
else
{
// fast path, straight to CG without per-glyph transforms
}
return;
}
static JNF_CLASS_CACHE(jc_StandardGlyphVector_GlyphTransformInfo, "sun/font/StandardGlyphVector$GlyphTransformInfo");
static JNF_MEMBER_CACHE(jm_StandardGlyphVector_GlyphTransformInfo_transforms, jc_StandardGlyphVector_GlyphTransformInfo, "transforms", "[D");
jdoubleArray g_gtiTransformsArray = JNFGetObjectField(env, gti, jm_StandardGlyphVector_GlyphTransformInfo_transforms); //(*env)->GetObjectField(env, gti, g_gtiTransforms);
jdouble *g_gvTransformsAsDoubles = (*env)->GetPrimitiveArrayCritical(env, g_gtiTransformsArray, NULL);
static JNF_MEMBER_CACHE(jm_StandardGlyphVector_GlyphTransformInfo_indices, jc_StandardGlyphVector_GlyphTransformInfo, "indices", "[I");
jintArray g_gtiTXIndicesArray = JNFGetObjectField(env, gti, jm_StandardGlyphVector_GlyphTransformInfo_indices);
// slowest case, we have per-glyph transforms, and possibly glyph substitution as well
JavaCT_DrawGlyphVector(qsdo, strike, useSubstituion, uniChars, glyphs, advances, g_gvTXIndicesAsInts, g_gvTransformsAsDoubles, length);
(*env)->ReleasePrimitiveArrayCritical(env, g_gtiTransformsArray, g_gvTransformsAsDoubles, JNI_ABORT);
}
// Retrieves advances for translated unicodes
// Uses "glyphs" as a temporary buffer for the glyph-to-unicode translation
(const NSFont *font, const int uniChars[], CGGlyph glyphs[], const size_t length, CGSize advances[])
{
// cycle over each spot, and if we discovered a unicode to substitute, we have to calculate the advance for it
size_t i;
for (i = 0; i < length; i++)
{
if (uniChar == 0) continue;
if (fallback) {
}
}
}
// Fills the glyph buffer with glyphs from the GlyphVector object. Also checks to see if the glyph's positions have been
// already caculated from GlyphVector, or we simply ask Core Graphics to make some advances for us. Pre-calculated positions
// are translated into advances, since CG only understands advances.
static inline void doDrawGlyphsPipe_fillGlyphAndAdvanceBuffers
(JNIEnv *env, QuartzSDOps *qsdo, const AWTStrike *strike, jobject gVector, CGGlyph *glyphs, int *uniChars, CGSize *advances, size_t length, jintArray glyphsArray)
{
// fill the glyph buffer
// if a glyph code from Java is negative, that means it is really a unicode value
// which we can use in CoreText to strike the character in another font
size_t i;
for (i = 0; i < length; i++)
{
if (code < 0)
{
glyphs[i] = 0;
}
else
{
uniChars[i] = 0;
}
}
// fill the advance buffer
static JNF_MEMBER_CACHE(jm_StandardGlyphVector_positions, jc_StandardGlyphVector, "positions", "[F");
{
// in this case, the positions have already been pre-calculated for us on the Java side
// <rdar://problem/4294061> take the first point, and move the context to that location
// for each position, figure out the advance (since CG won't take positions directly)
size_t i;
{
}
}
else
{
// in this case, we have to go and calculate the positions ourselves
// there were no pre-calculated positions from the glyph buffer on the Java side
CTFontGetAdvancesForGlyphs((CTFontRef)awtFont->fFont, kCTFontDefaultOrientation, glyphs, advances, length);
if (complex)
{
}
}
// continue on to the next stage of the pipe
doDrawGlyphsPipe_checkForPerGlyphTransforms(env, qsdo, strike, gVector, complex, uniChars, glyphs, advances, length);
}
// Obtains the glyph array to determine the number of glyphs we are dealing with. If we are dealing a large number of glyphs,
// we malloc a buffer to hold the glyphs and their advances, otherwise we use stack allocated buffers.
static inline void doDrawGlyphsPipe_getGlyphVectorLengthAndAlloc
{
if (length == 0)
{
// nothing to draw
return;
}
{
// if we are small enough, fit everything onto the stack
doDrawGlyphsPipe_fillGlyphAndAdvanceBuffers(env, qsdo, strike, gVector, glyphs, uniChars, advances, length, glyphsArray);
}
else
{
// otherwise, we should malloc and free buffers for this large run
{
return;
}
doDrawGlyphsPipe_fillGlyphAndAdvanceBuffers(env, qsdo, strike, gVector, glyphs, uniChars, advances, length, glyphsArray);
}
}
// Setup and save the state of the CGContext, and apply any java.awt.Font transforms to the context.
static inline void doDrawGlyphsPipe_applyFontTransforms
(JNIEnv *env, QuartzSDOps *qsdo, const AWTStrike *strike, jobject gVector, const jfloat x, const jfloat y)
{
}
/*
* Class: sun_lwawt_macosx_CTextPipe
* Method: doDrawString
*/
(JNIEnv *env, jobject jthis, jobject jsurfacedata, jlong awtStrikePtr, jstring str, jdouble x, jdouble y)
{
if (len < MAX_STACK_ALLOC_GLYPH_BUFFER_SIZE) // optimized for stack allocation <rdar://problem/4285041>
{
// Draw the text context
}
else
{
// Get string to draw and the length
// Draw the text context
}
}
/*
* Class: sun_lwawt_macosx_CTextPipe
* Method: doUnicodes
* Signature: (Lsun/java2d/SurfaceData;J[CIIFF)V
*/
(JNIEnv *env, jobject jthis, jobject jsurfacedata, jlong awtStrikePtr, jcharArray unicodes, jint offset, jint length, jfloat x, jfloat y)
{
// Setup the text context
{
}
else
{
if (!copyUnichars) {
[JNFException raise:env as:kOutOfMemoryError reason:"Failed to malloc memory to create the glyphs for string drawing"];
}
@try {
} @finally {
}
}
}
/*
* Class: sun_lwawt_macosx_CTextPipe
* Method: doOneUnicode
* Signature: (Lsun/java2d/SurfaceData;JCFF)V
*/
(JNIEnv *env, jobject jthis, jobject jsurfacedata, jlong awtStrikePtr, jchar aUnicode, jfloat x, jfloat y)
{
}
/*
* Class: sun_lwawt_macosx_CTextPipe
* Method: doDrawGlyphs
* Signature: (Lsun/java2d/SurfaceData;JLjava/awt/font/GlyphVector;FF)V
*/
(JNIEnv *env, jobject jthis, jobject jsurfacedata, jlong awtStrikePtr, jobject gVector, jfloat x, jfloat y)
{
{
return;
}
JRSFontSetRenderingStyleOnContext(qsdo->cgRef, JRSFontGetRenderingStyleForHints(sun_awt_SunHints_INTVAL_FRACTIONALMETRICS_ON, sun_awt_SunHints_INTVAL_TEXT_ANTIALIAS_ON));
}