1 /*
   2  * Copyright (c) 2013, 2014, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  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 package com.sun.javafx.font.coretext;
  27 
  28 import java.nio.ByteOrder;
  29 import java.security.AccessController;
  30 import java.security.PrivilegedAction;
  31 
  32 import com.sun.glass.utils.NativeLibLoader;
  33 import com.sun.javafx.geom.Path2D;
  34 
  35 class OS {
  36     static {
  37         AccessController.doPrivileged((PrivilegedAction<Void>) () -> {
  38             NativeLibLoader.loadLibrary("javafx_font");
  39             return null;
  40         });
  41     }
  42 
  43     static final int kCFURLPOSIXPathStyle = 0;
  44     static final int kCTFontOrientationDefault = 0;
  45     static final int kCTFontManagerScopeProcess = 1;
  46     static final int kCGBitmapByteOrder32Big = 4 << 12;
  47     static final int kCGBitmapByteOrder32Little = 2 << 12;
  48     static final int kCGBitmapByteOrder32Host = ByteOrder.nativeOrder() == ByteOrder.LITTLE_ENDIAN ? kCGBitmapByteOrder32Little : kCGBitmapByteOrder32Big;
  49     static final int kCGImageAlphaPremultipliedFirst = 2;
  50     static final int kCGImageAlphaNone = 0;
  51     static final int kCTWritingDirectionRightToLeft = 1;
  52 
  53     static final long CFStringCreate(String string) {
  54         char[] buffer = string.toCharArray();
  55         long alloc = kCFAllocatorDefault();
  56         return CFStringCreateWithCharacters(alloc, buffer, buffer.length);
  57     }
  58 
  59     /* Custom */
  60     static final native byte[] CGBitmapContextGetData(long c, int width, int height, int bpp);
  61     static final native void CGRectApplyAffineTransform(CGRect rect, CGAffineTransform t);
  62     static final native Path2D CGPathApply(long path);
  63     static final native CGRect CGPathGetPathBoundingBox(long path);
  64     static final native long CFStringCreateWithCharacters(long alloc, char[] chars, long start, long numChars);
  65     static final native String CTFontCopyAttributeDisplayName(long font);
  66     static final native void CTFontDrawGlyphs(long font, short glyphs, double x, double y, long context);
  67     static final native double CTFontGetAdvancesForGlyphs(long font, int orientation, short glyphs, CGSize advances);
  68     static final native boolean CTFontGetBoundingRectForGlyphUsingTables(long font, short glyphs, short format, int[] retArr);
  69     static final native int CTRunGetGlyphs(long run, int slotMask, int start, int[] buffer);
  70     static final native int CTRunGetStringIndices(long run, int start, int[] buffer);
  71     static final native int CTRunGetPositions(long run, int start, float[] buffer);
  72 
  73     /* one to one */
  74     static final native long kCFAllocatorDefault();
  75     static final native long kCFTypeDictionaryKeyCallBacks();
  76     static final native long kCFTypeDictionaryValueCallBacks();
  77     static final native long kCTFontAttributeName();
  78     static final native long kCTParagraphStyleAttributeName();
  79     static final native long CFArrayGetCount(long theArray);
  80     static final native long CFArrayGetValueAtIndex(long theArray, long idx);
  81     static final native long CFAttributedStringCreate(long alloc, long str, long attributes);
  82     static final native void CFDictionaryAddValue(long theDict, long key, long value);
  83     static final native long CFDictionaryCreateMutable(long allocator, long capacity, long keyCallBacks, long valueCallBacks);
  84     static final native long CFDictionaryGetValue(long theDict, long key);
  85     static final native void CFRelease(long cf);
  86     static final native long CFStringCreateWithCharacters(long alloc, char[] chars, long numChars);
  87     static final native long CFURLCreateWithFileSystemPath(long allocator, long filePath, long pathStyle, boolean isDirectory);
  88     static final native long CGBitmapContextCreate(long data, long width, long height, long bitsPerComponent, long bytesPerRow, long colorspace, int bitmapInfo);
  89     static final native void CGContextFillRect(long context, CGRect rect);
  90     static final native void CGContextRelease(long context);
  91     static final native void CGContextSetAllowsFontSmoothing(long context, boolean allowsFontSmoothing);
  92     static final native void CGContextSetAllowsAntialiasing(long context, boolean allowsAntialiasing);
  93     static final native void CGContextSetAllowsFontSubpixelPositioning(long context, boolean allowsFontSubpixelPositioning);
  94     static final native void CGContextSetAllowsFontSubpixelQuantization(long context, boolean allowsFontSubpixelQuantization);
  95     static final native void CGContextSetRGBFillColor(long context, double red, double green, double blue, double alpha);
  96     static final native void CGContextTranslateCTM(long context, double tx, double ty);
  97     static final native long CGColorSpaceCreateDeviceGray();
  98     static final native long CGColorSpaceCreateDeviceRGB();
  99     static final native void CGColorSpaceRelease(long space);
 100     static final native void CGPathRelease(long path);
 101     static final native long CTFontCreateWithName(long name, double size, CGAffineTransform matrix);
 102     static final native long CTFontCreatePathForGlyph(long font, short glyph, CGAffineTransform matrix);
 103     static final native boolean CTFontManagerRegisterFontsForURL(long fontURL, int scope, long error);
 104     static final native long CTLineCreateWithAttributedString(long string);
 105     static final native long CTLineGetGlyphRuns(long line);
 106     static final native long CTLineGetGlyphCount(long line);
 107     static final native double CTLineGetTypographicBounds(long line);
 108     static final native long CTRunGetGlyphCount(long run);
 109     static final native long CTRunGetAttributes(long run);
 110     static final native long CTParagraphStyleCreate(int dir);
 111 
 112 }