4632N/A * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. 4632N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4632N/A * This code is free software; you can redistribute it and/or modify it 4632N/A * under the terms of the GNU General Public License version 2 only, as 4632N/A * published by the Free Software Foundation. Oracle designates this 4632N/A * particular file as subject to the "Classpath" exception as provided 4632N/A * by Oracle in the LICENSE file that accompanied this code. 4632N/A * This code is distributed in the hope that it will be useful, but WITHOUT 4632N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 4632N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 4632N/A * version 2 for more details (a copy is included in the LICENSE file that 4632N/A * You should have received a copy of the GNU General Public License version 4632N/A * 2 along with this work; if not, write to the Free Software Foundation, 4632N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 4632N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 4632N/A * or visit www.oracle.com if you need additional information or have any 4632N/A#
import "fontscalerdefs.h" // contains the definition of GlyphInfo struct 4632N/A#
import "sun_awt_SunHints.h" 4632N/A//#define USE_IMAGE_ALIGNED_MEMORY 1 4632N/A//#define CGGI_DEBUG_HIT_COUNT 1 4632N/A NSLog(@
"(%f, %f, %f, %f, %f, %f)", x.a, x.b, x.c, x.d, x.
tx, x.
ty);
4632N/A * The GlyphCanvas is a global shared CGContext that characters are struck into. 4632N/A * For each character, the glyph is struck, copied into a GlyphInfo struct, and 4632N/A * the canvas is cleared for the next glyph. 4632N/A * If the necessary canvas is too large, the shared one will not be used and a 4632N/A * temporary one will be provided. 4632N/A * These debug functions are only compiled when CGGI_DEBUG is activated. 4632N/A * They will print out a full UInt8 canvas and any pixels struck (assuming 4632N/A * the canvas is not too big). 4632N/A * As another debug feature, the entire canvas will be filled with a light 4632N/A * alpha value so it is easy to see where the glyph painting regions are 4632N/A fprintf(
stderr,
" [linewidth: %f] [linecap: %d] [linejoin: %d] [miterlimit: %f] [dashcount: %lu]\n",
4632N/A fprintf(
stderr,
" [smoothness: %f] [antialias: %d] [smoothfont: %d] [fontrenderingmode: %d]\n",
4632N/A // UInt32 p = src[srcRow + x]; 4632N/A // dest[destRow + x3] = 0xFF - (p >> 16 & 0xFF); 4632N/A // dest[destRow + x3 + 1] = 0xFF - (p >> 8 & 0xFF); 4632N/A // dest[destRow + x3 + 2] = 0xFF - (p & 0xFF); 4632N/A//static void CGGI_copyImageFromCanvasToAlphaInfo 4632N/A//(CGGI_GlyphCanvas *canvas, GlyphInfo *info) 4632N/A// vImage_Buffer infoBuffer; 4632N/A// infoBuffer.data = info->image; 4632N/A// infoBuffer.width = info->width; 4632N/A// infoBuffer.height = info->height; 4632N/A// infoBuffer.rowBytes = info->width; // three bytes per RGB pixel 4632N/A// UInt8 scrapPixel[info->width * info->height]; 4632N/A// vImage_Buffer scrapBuffer; 4632N/A// scrapBuffer.data = &scrapPixel; 4632N/A// scrapBuffer.width = info->width; 4632N/A// scrapBuffer.height = info->height; 4632N/A// scrapBuffer.rowBytes = info->width; 4632N/A// vImageConvert_ARGB8888toPlanar8(canvas->image, &infoBuffer, 4632N/A// &scrapBuffer, &scrapBuffer, &scrapBuffer, kvImageNoFlags); 4632N/A return 0xFF - ((p >>
24 &
0xFF) + (p >>
16 &
0xFF) + (p >>
8 &
0xFF)) /
3;
4632N/A return 0xFF - ((p >>
16 &
0xFF) + (p >>
8 &
0xFF) + (p &
0xFF)) /
3;
4632N/A * Creates a new canvas of a fixed size, and initializes the CGContext as 4632N/A * an 32-bit ARGB BitmapContext with some generic RGB color space. 4632N/A // our canvas is *always* 4-byte ARGB 4632N/A * Releases the BitmapContext and the associated memory backing it. 4632N/A * This is the slack space that is preallocated for the global GlyphCanvas 4632N/A * when it needs to be expanded. It has been set somewhat liberally to 4632N/A * avoid re-upsizing frequently. 4632N/A * Quick and easy inline to check if this canvas is big enough. 4632N/A // if we don't have enough space to strike the largest glyph in the 4632N/A * Clear the canvas by blitting white only into the region of interest 4632N/A * (the rect which we will copy out of once the glyph is struck). 4632N/A // use the row stride of the canvas, not the info 4632N/A * Creates a GlyphInfo with exactly the correct size image and measurements. 4632N/A // adjust the bounding box to be 1px bigger on each side than what 4632N/A // CGFont-whatever suggests - because it gives a bounding box that 4632N/A // if the glyph is larger than 1MB, don't even try... 4632N/A // the GlyphVector path should have taken over by now 4632N/A // create a GlyphInfo struct fused to the image it points to 4632N/A * Clears the canvas, strikes the glyph with CoreGraphics, and then 4632N/A * copies the struck pixels into the GlyphInfo image. 4632N/A // strike the glyph in the upper right corner 4632N/A // copy the glyph from the canvas into the info 4632N/A // save the state of the world 4632N/A // get the glyph, measure it using CG 4632N/A // create the Sun2D GlyphInfo we are going to strike into 4632N/A // fix the context size, just in case the substituted character is unexpectedly large 4632N/A // align the transform for the real CoreText strike 4632N/A // clean the canvas - align, strike, and copy the glyph from the canvas into the info 4632N/A // restore the state of the world 4632N/A * Sets all the per-run properties for the canvas, and then iterates through 4632N/A * the character run, and creates images in the GlyphInfo structs. 4632N/A * Not inlined because it would create two copies in the function below 4632N/A @
"Java CoreGraphics Text Renderer Cached Canvas";
4632N/A * This is the maximum length and height times the above slack squared 4632N/A * to determine if we go with the global canvas, or malloc one on the spot. 4632N/A * Based on the space needed to strike the largest character in the run, 4632N/A * either use the global shared canvas, or make one up on the spot, strike 4632N/A * the glyphs, and destroy it. 4632N/A * Finds the advances and bounding boxes of the characters in the run, 4632N/A * cycles through all the bounds and calculates the maximum canvas space 4632N/A * required by the largest glyph. 4632N/A * Creates a GlyphInfo struct with a malloc that also encapsulates the 4632N/A * image the struct points to. This is done to meet memory layout 4632N/A * expectations in the Sun text rasterizer memory managment code. 4632N/A * The image immediately follows the struct physically in memory. 4632N/A continue;
// will be handled later 4632N/A * This stage separates the already valid glyph codes from the unicode values 4632N/A * that need special handling - the rawGlyphCodes array is no longer used 4632N/A * Conditionally stack allocates buffers for glyphs, bounding boxes, 4632N/A * and advances. Unfortunately to use CG or CT in bulk runs (which is 4632N/A * faster than calling them per character), we have to copy into and out 4632N/A * of these buffers. Still a net win though. 4632N/A // just do one malloc, and carve it up for all the buffers