Imported Upstream version 3.6.0

Former-commit-id: da6be194a6b1221998fc28233f2503bd61dd9d14
This commit is contained in:
Jo Shields
2014-08-13 10:39:27 +01:00
commit a575963da9
50588 changed files with 8155799 additions and 0 deletions

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,30 @@
/*
Copyright (C) 2011 Volker Berlin (i-net software)
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
Jeroen Frijters
jeroen@frijters.net
*/
package sun.awt;
import sun.font.SunFontManager;
public class Win32FontManager extends SunFontManager {
}

View File

@@ -0,0 +1,30 @@
/*
Copyright (C) 2011 Volker Berlin (i-net software)
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
Jeroen Frijters
jeroen@frijters.net
*/
package sun.awt;
import sun.font.SunFontManager;
public class X11FontManager extends SunFontManager {
}

View File

@@ -0,0 +1,38 @@
/*
Copyright (C) 2010 Volker Berlin (i-net software)
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
Jeroen Frijters
jeroen@frijters.net
*/
package sun.awt.image;
import java.io.InputStream;
/**
* Replace the same class from Sun with native parts.
* @author Volker Berlin
*/
public class GifImageDecoder extends IkvmImageDecoder{
GifImageDecoder(InputStreamImageSource src, InputStream is){
super(src, is);
}
}

View File

@@ -0,0 +1,150 @@
/*
Copyright (C) 2010 Volker Berlin (i-net software)
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
Jeroen Frijters
jeroen@frijters.net
*/
package sun.awt.image;
import java.awt.image.*;
import java.io.IOException;
import java.io.InputStream;
import cli.System.Drawing.Bitmap;
import cli.System.Drawing.Imaging.ImageLockMode;
import cli.System.Drawing.Imaging.PixelFormat;
import cli.System.IO.SeekOrigin;
import cli.System.IO.Stream;
import cli.System.NotSupportedException;
import ikvm.runtime.Util;
abstract class IkvmImageDecoder extends ImageDecoder {
IkvmImageDecoder(InputStreamImageSource src, InputStream is){
super(src, is);
}
@Override
@cli.System.Security.SecuritySafeCriticalAttribute.Annotation
public void produceImage() throws IOException, ImageFormatException{
Stream stream = new Stream(){
@Override
public void Flush(){
Util.throwException(new NotSupportedException());
}
@Override
public int Read(byte[] bytes, int off, int len){
try{
int count = input.read(bytes, off, len);
if( count < 0 ){
return 0;
}
return count;
}catch(IOException ex){
throw new RuntimeException(ex);
}
}
@Override
public long Seek(long arg0, SeekOrigin arg1){
Util.throwException(new NotSupportedException());
return 0;
}
@Override
public void SetLength(long arg0){
Util.throwException(new NotSupportedException());
}
@Override
public void Write(byte[] arg0, int arg1, int arg2){
Util.throwException(new NotSupportedException());
}
@Override
public boolean get_CanRead(){
return true;
}
@Override
public boolean get_CanSeek(){
return false;
}
@Override
public boolean get_CanWrite(){
return true;
}
@Override
public long get_Length(){
try{
return input.available();
}catch(IOException ex){
throw new RuntimeException(ex);
}
}
@Override
public long get_Position(){
Util.throwException(new NotSupportedException());
return 0;
}
@Override
public void set_Position(long arg0){
Util.throwException(new NotSupportedException());
}
};
try{
Bitmap bitmap = new Bitmap(stream);
int width = bitmap.get_Width();
int height = bitmap.get_Height();
int size = width * height;
int[] pixelData = new int[size];
cli.System.Drawing.Rectangle rect = new cli.System.Drawing.Rectangle(0, 0, width, height);
cli.System.Drawing.Imaging.BitmapData data = bitmap.LockBits(rect, ImageLockMode.wrap(ImageLockMode.ReadOnly), PixelFormat.wrap(PixelFormat.Format32bppArgb));
cli.System.IntPtr pixelPtr = data.get_Scan0();
cli.System.Runtime.InteropServices.Marshal.Copy(pixelPtr, pixelData, 0, size);
bitmap.UnlockBits(data);
//source.
setDimensions(width, height);
ColorModel cm = ColorModel.getRGBdefault();
setColorModel(cm);
//setHints(flags);
headerComplete();
setPixels(0,0,width,height, cm, pixelData,0,width);
imageComplete(ImageConsumer.STATICIMAGEDONE, true);
}catch(Throwable th){
th.printStackTrace();
imageComplete(ImageConsumer.IMAGEERROR|ImageConsumer.STATICIMAGEDONE, true);
throw new IOException(th);
} finally {
try { close(); } catch(Throwable e){e.printStackTrace();}
}
}
}

View File

@@ -0,0 +1,421 @@
/*
Copyright (C) 2009 Jeroen Frijters
Copyright (C) 2010 Volker Berlin (i-net software)
Copyright (C) 2011 Karsten Heinrich (i-net software)
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
Jeroen Frijters
jeroen@frijters.net
*/
package sun.awt.image;
import java.awt.image.BufferedImage;
import java.awt.image.ColorModel;
import java.awt.image.ImageConsumer;
import java.awt.image.ImageObserver;
import java.util.Hashtable;
import cli.System.Drawing.Bitmap;
import cli.System.Drawing.Imaging.BitmapData;
import cli.System.Drawing.Imaging.ImageLockMode;
import cli.System.Drawing.Imaging.PixelFormat;
public class ImageRepresentation extends ImageWatched implements ImageConsumer{
private static final int DEFAULT_PIXEL_FORMAT = PixelFormat.Format32bppArgb;
InputStreamImageSource src;
ToolkitImage image;
private int width = -1;
private int height = -1;
private int availinfo;
private BufferedImage bimage;
private cli.System.Drawing.Bitmap bitmap;
private int pixelFormat = DEFAULT_PIXEL_FORMAT;
ImageRepresentation(ToolkitImage im){
image = im;
if (image.getSource() instanceof InputStreamImageSource) {
src = (InputStreamImageSource) image.getSource();
}
}
/* REMIND: Only used for Frame.setIcon - should use ImageWatcher instead */
public synchronized void reconstruct(int flags) {
if (src != null) {
src.checkSecurity(null, false);
}
int missinginfo = flags & ~availinfo;
if ((availinfo & ImageObserver.ERROR) == 0 && missinginfo != 0) {
numWaiters++;
try {
startProduction();
missinginfo = flags & ~availinfo;
while ((availinfo & ImageObserver.ERROR) == 0 &&
missinginfo != 0)
{
try {
wait();
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
return;
}
missinginfo = flags & ~availinfo;
}
} finally {
decrementWaiters();
}
}
}
@Override
public void setDimensions(int w, int h){
if (src != null) {
src.checkSecurity(null, false);
}
image.setDimensions(w, h);
// bitmap = new cli.System.Drawing.Bitmap(w, h);
newInfo(image, (ImageObserver.WIDTH | ImageObserver.HEIGHT),
0, 0, w, h);
if (w <= 0 || h <= 0) {
imageComplete(ImageConsumer.IMAGEERROR);
return;
}
width = w;
height = h;
availinfo |= ImageObserver.WIDTH | ImageObserver.HEIGHT;
}
private Bitmap getBitmapRef(){
if( bitmap == null ){
bitmap = new Bitmap(width, height, PixelFormat.wrap(pixelFormat) );
}
return bitmap;
}
public int getWidth(){
return width;
}
public int getHeight(){
return height;
}
public BufferedImage getBufferedImage(){
return bimage;
}
@Override
public void setProperties(Hashtable<?, ?> props){
// ignore it
}
@Override
public synchronized void setColorModel(ColorModel model){
int newPixelFormat = getPixelFormatForColorModel(model);
if( model.getPixelSize() <= 8 ){
newPixelFormat = DEFAULT_PIXEL_FORMAT;
}
if( newPixelFormat != pixelFormat && bitmap != null ){
// force reconstruct of the bitmap due to a color model change
bitmap.Dispose();
bitmap = null;
}
pixelFormat = newPixelFormat;
}
@Override
public void setHints(int hintflags){
// ignore it
}
@Override
public void setPixels(int x, int y, int w, int h, ColorModel model, byte[] pixels, int off, int scansize){
int[] pixeli = new int[pixels.length];
for (int i = 0; i < pixels.length; i++)
{
pixeli[i] = model.getRGB(pixels[i] & 0xff);
}
setPixels(x, y, w, h, model, pixeli, off, scansize);
}
@Override
@cli.System.Security.SecuritySafeCriticalAttribute.Annotation
public void setPixels(int x, int y, int w, int h, ColorModel model, int[] pixels, int off, int scansize){
// FIXME this method will fail for scan lines
if( x < 0) {
w -= x;
x = 0;
}
if (y < 0) {
h -= y;
y = 0;
}
if (w <= 0 || h <= 0) {
// nothing to set
return;
}
if ( off < 0 ) {
throw new java.lang.ArrayIndexOutOfBoundsException( "Data offset out of bounds." );
}
long length = w * h;
if (length > pixels.length - off)
{
throw new java.lang.ArrayIndexOutOfBoundsException("Data offset out of bounds.");
}
synchronized (this)
{
int pixelFormat = getPixelFormatForColorModel( model );
int bpp = model.getPixelSize();
if( bpp == 32 ){ // 32 can be copies 1:1 using an int array
copyInt(x, y, w, h, pixels, off, pixelFormat);
}else if( bpp <= 8 ){
// transform all pixels using the color model (for indexed color models)
int[] newData = new int[pixels.length];
for( int i=0; i < newData.length; i++ ){
newData[i] = model.getRGB(pixels[i]);
}
copyInt(x, y, w, h, pixels, off, DEFAULT_PIXEL_FORMAT);
}else {
// byte per scanline, must be a multitude of 4
// see http://stackoverflow.com/questions/2185944/why-must-stride-in-the-system-drawing-bitmap-constructor-be-a-multiple-of-4
int bytesPerLine = (bpp * w) / 8;
int scanLine = ((bytesPerLine + 3) / 4) * 4;
int offset = scanLine - bytesPerLine;
byte[] newData = new byte[h * scanLine];
int position = 0;
int pixel;
for( int i=0; i<pixels.length; i++ ){
pixel = pixels[i];
switch( bpp ){
case 16: newData[position] = (byte)(pixel & 0xFF);
newData[position + 1] = (byte)((pixel >> 8) & 0xFF); break;
case 24: newData[position] = (byte)(pixel & 0xFF);
newData[position + 1] = (byte)((pixel >> 8) & 0xFF);
newData[position + 2] = (byte)((pixel >> 16) & 0xFF); break;
}
position += bpp / 8;
if( position % scanLine == bytesPerLine ){
position += offset;
}
}
copyByte(x, y, w, h, newData, off, pixelFormat, bpp);
}
}
availinfo |= ImageObserver.SOMEBITS;
// Can't do this here since we might need to transform/clip
// the region
if (((availinfo & ImageObserver.FRAMEBITS) == 0)) {
newInfo(image, ImageObserver.SOMEBITS, x, y, w, h);
}
}
@cli.System.Security.SecurityCriticalAttribute.Annotation
private void copyInt(int x, int y, int w, int h, int[] pixels, int off, int pixelFormat ) {
BitmapData data = getBitmapRef().LockBits(new cli.System.Drawing.Rectangle(x, y, w, h), ImageLockMode.wrap(ImageLockMode.WriteOnly), PixelFormat.wrap(pixelFormat));
cli.System.Runtime.InteropServices.Marshal.Copy(pixels, off, data.get_Scan0(), data.get_Width() * data.get_Height());
getBitmapRef().UnlockBits(data);
}
@cli.System.Security.SecurityCriticalAttribute.Annotation
private void copyByte(int x, int y, int w, int h, byte[] pixels, int off, int pixelFormat, int bpp) {
BitmapData data = getBitmapRef().LockBits(new cli.System.Drawing.Rectangle(x, y, w, h), ImageLockMode.wrap(ImageLockMode.WriteOnly), PixelFormat.wrap(pixelFormat));
cli.System.Runtime.InteropServices.Marshal.Copy(pixels, off, data.get_Scan0(), pixels.length);
getBitmapRef().UnlockBits(data);
}
private int getPixelFormatForColorModel( ColorModel cm ){
if( cm == null ){
return DEFAULT_PIXEL_FORMAT; // TODO is PixelFormat.Canonical better here?
}
int bpp = cm.getPixelSize();
int[] sizes = cm.getComponentSize();
switch( bpp ){
case 1: return PixelFormat.Undefined; // Indexed is invalid and there is no 1bpp
case 4: return PixelFormat.Format4bppIndexed;
case 8: return PixelFormat.Format8bppIndexed;
case 16:
if( sizes.length <= 1) {
return PixelFormat.Format16bppGrayScale;
}
if( sizes.length == 3 ){
if( sizes[0] == 5 && sizes[2] == 5 ){
return sizes[1] == 5 ? PixelFormat.Format16bppRgb555 : PixelFormat.Format16bppRgb565;
}
}
if( sizes.length == 4 && cm.hasAlpha() ){
return PixelFormat.Format16bppArgb1555;
}
break;
case 24:
return PixelFormat.Format24bppRgb;
case 32:
if(!cm.hasAlpha()){
return PixelFormat.Format32bppRgb;
} else {
return cm.isAlphaPremultiplied() ? PixelFormat.Format32bppPArgb : PixelFormat.Format32bppArgb;
}
case 48:
return PixelFormat.Format48bppRgb;
case 64:
return cm.isAlphaPremultiplied() ? PixelFormat.Format64bppPArgb : PixelFormat.Format64bppArgb;
}
return PixelFormat.Undefined;
}
private boolean consuming = false;
public void imageComplete(int status) {
if (src != null) {
src.checkSecurity(null, false);
}
boolean done;
int info;
switch (status) {
default:
case ImageConsumer.IMAGEABORTED:
done = true;
info = ImageObserver.ABORT;
break;
case ImageConsumer.IMAGEERROR:
image.addInfo(ImageObserver.ERROR);
done = true;
info = ImageObserver.ERROR;
dispose();
break;
case ImageConsumer.STATICIMAGEDONE:
done = true;
info = ImageObserver.ALLBITS;
break;
case ImageConsumer.SINGLEFRAMEDONE:
done = false;
info = ImageObserver.FRAMEBITS;
break;
}
synchronized (this) {
if (done) {
image.getSource().removeConsumer(this);
consuming = false;
}
if (bimage == null ) {
bimage = new BufferedImage(getBitmapRef());
}
availinfo |= info;
notifyAll();
}
newInfo(image, info, 0, 0, width, height);
image.infoDone(status);
}
/*synchronized*/ void startProduction() {
if (!consuming) {
consuming = true;
image.getSource().startProduction(this);
}
}
private int numWaiters;
private synchronized void checkConsumption() {
if (isWatcherListEmpty() && numWaiters == 0 &&
((availinfo & ImageObserver.ALLBITS) == 0))
{
dispose();
}
}
@Override
public synchronized void notifyWatcherListEmpty() {
checkConsumption();
}
private synchronized void decrementWaiters() {
--numWaiters;
checkConsumption();
}
public boolean prepare(ImageObserver iw) {
if (src != null) {
src.checkSecurity(null, false);
}
if ((availinfo & ImageObserver.ERROR) != 0) {
if (iw != null) {
iw.imageUpdate(image, ImageObserver.ERROR|ImageObserver.ABORT,
-1, -1, -1, -1);
}
return false;
}
boolean done = ((availinfo & ImageObserver.ALLBITS) != 0);
if (!done) {
addWatcher(iw);
startProduction();
// Some producers deliver image data synchronously
done = ((availinfo & ImageObserver.ALLBITS) != 0);
}
return done;
}
public int check(ImageObserver iw) {
if (src != null) {
src.checkSecurity(null, false);
}
if ((availinfo & (ImageObserver.ERROR | ImageObserver.ALLBITS)) == 0) {
addWatcher(iw);
}
return availinfo;
}
synchronized void abort() {
image.getSource().removeConsumer(this);
consuming = false;
bimage = null;
bitmap = null;
newInfo(image, ImageObserver.ABORT, -1, -1, -1, -1);
availinfo &= ~(ImageObserver.SOMEBITS
| ImageObserver.FRAMEBITS
| ImageObserver.ALLBITS
| ImageObserver.ERROR);
}
synchronized void dispose() {
image.getSource().removeConsumer(this);
consuming = false;
availinfo &= ~(ImageObserver.SOMEBITS
| ImageObserver.FRAMEBITS
| ImageObserver.ALLBITS);
}
}

View File

@@ -0,0 +1,67 @@
/*
* Copyright (c) 1997, 2007, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* 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.
*/
package sun.awt.image;
import java.awt.geom.AffineTransform;
import java.awt.image.AffineTransformOp;
import java.awt.image.BufferedImage;
import java.awt.image.BufferedImageOp;
import java.awt.image.ByteLookupTable;
import java.awt.image.ConvolveOp;
import java.awt.image.Kernel;
import java.awt.image.LookupOp;
import java.awt.image.LookupTable;
import java.awt.image.RasterOp;
import java.awt.image.Raster;
import java.awt.image.WritableRaster;
import java.security.AccessController;
import java.security.PrivilegedAction;
/**
* This class provides a hook to access platform-specific
* imaging code.
*
* If the implementing class cannot handle the op, tile format or
* image format, the method will return null;
* If there is an error when processing the
* data, the implementing class may either return null
* (in which case our java code will be executed) or may throw
* an exception.
*/
public class ImagingLib {
public static WritableRaster filter(RasterOp op, Raster src,
WritableRaster dst) {
return null;
}
public static BufferedImage filter(BufferedImageOp op, BufferedImage src,
BufferedImage dst)
{
return null;
}
}

View File

@@ -0,0 +1,38 @@
/*
Copyright (C) 2010 Volker Berlin (i-net software)
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
Jeroen Frijters
jeroen@frijters.net
*/
package sun.awt.image;
import java.io.InputStream;
/**
* Replace the same class from Sun with native parts.
* @author Volker Berlin
*/
public class JPEGImageDecoder extends IkvmImageDecoder{
JPEGImageDecoder(InputStreamImageSource src, InputStream is){
super(src, is);
}
}

View File

@@ -0,0 +1,139 @@
/*
* Copyright (c) 2001, 2007, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* 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.
*/
package sun.awt.image;
import java.awt.Point;
import java.awt.Rectangle;
import java.awt.Image;
import java.awt.image.DataBuffer;
import java.awt.image.DataBufferByte;
import java.awt.image.DataBufferUShort;
import java.awt.image.DataBufferInt;
import java.awt.image.SampleModel;
import java.awt.image.WritableRaster;
import sun.java2d.StateTrackable.State;
//import sun.java2d.SurfaceData;
import sun.java2d.StateTrackableDelegate;
/**
* This class exists as a middle layer between WritableRaster and its
* implementation specific subclasses (ByteComponentRaster, ShortBandedRaster,
* etc).
* It provides utilities to steal the data arrays from the standard DataBuffer
* types and also steals the StateTrackableDelegate from the associated
* DataBuffer so that it can be updated when the data is changed.
*/
public class SunWritableRaster extends WritableRaster {
private static DataStealer stealer;
public static interface DataStealer {
public byte[] getData(DataBufferByte dbb, int bank);
public short[] getData(DataBufferUShort dbus, int bank);
public int[] getData(DataBufferInt dbi, int bank);
public StateTrackableDelegate getTrackable(DataBuffer db);
public void setTrackable(DataBuffer db, StateTrackableDelegate trackable);
}
public static void setDataStealer(DataStealer ds) {
if (stealer != null) {
throw new InternalError("Attempt to set DataStealer twice");
}
stealer = ds;
}
public static byte[] stealData(DataBufferByte dbb, int bank) {
return stealer.getData(dbb, bank);
}
public static short[] stealData(DataBufferUShort dbus, int bank) {
return stealer.getData(dbus, bank);
}
public static int[] stealData(DataBufferInt dbi, int bank) {
return stealer.getData(dbi, bank);
}
public static StateTrackableDelegate stealTrackable(DataBuffer db) {
return stealer.getTrackable(db);
}
public static void markDirty(DataBuffer db) {
stealer.getTrackable(db).markDirty();
}
public static void setTrackable(DataBuffer db, StateTrackableDelegate trackable) {
stealer.setTrackable(db, trackable);
}
public static void makeTrackable(DataBuffer db) {
stealer.setTrackable(db, StateTrackableDelegate.createInstance(State.STABLE));
}
public static void markDirty(WritableRaster wr) {
if (wr instanceof SunWritableRaster) {
((SunWritableRaster) wr).markDirty();
} else {
markDirty(wr.getDataBuffer());
}
}
public static void markDirty(Image img) {
// SurfaceData.getPrimarySurfaceData(img).markDirty();
}
private StateTrackableDelegate theTrackable;
public SunWritableRaster(SampleModel sampleModel, Point origin) {
super(sampleModel, origin);
theTrackable = stealTrackable(dataBuffer);
}
public SunWritableRaster(SampleModel sampleModel,
DataBuffer dataBuffer,
Point origin)
{
super(sampleModel, dataBuffer, origin);
theTrackable = stealTrackable(dataBuffer);
}
public SunWritableRaster(SampleModel sampleModel,
DataBuffer dataBuffer,
Rectangle aRegion,
Point sampleModelTranslate,
WritableRaster parent)
{
super(sampleModel, dataBuffer, aRegion, sampleModelTranslate, parent);
theTrackable = stealTrackable(dataBuffer);
}
/**
* Mark the TrackableDelegate of the associated DataBuffer dirty.
*/
public final void markDirty() {
theTrackable.markDirty();
}
}

View File

@@ -0,0 +1,325 @@
/*
* Copyright (c) 1995, 2004, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* 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.
*/
package sun.awt.image;
import java.util.Hashtable;
import java.util.Enumeration;
import java.awt.Component;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.image.BufferedImage;
import java.awt.image.ColorModel;
import java.awt.image.ImageProducer;
import java.awt.image.ImageConsumer;
import java.awt.image.ImageObserver;
import sun.awt.image.ImageRepresentation;
public class ToolkitImage extends Image {
/**
* The object which is used to reconstruct the original image data
* as needed.
*/
ImageProducer source;
InputStreamImageSource src;
ImageRepresentation imagerep;
protected ToolkitImage() {
}
/**
* Construct an image from an ImageProducer object.
*/
public ToolkitImage(ImageProducer is) {
source = is;
if (is instanceof InputStreamImageSource) {
src = (InputStreamImageSource) is;
}
}
public ImageProducer getSource() {
if (src != null) {
src.checkSecurity(null, false);
}
return source;
}
private int width = -1;
private int height = -1;
private Hashtable properties;
private int availinfo;
/**
* Return the width of the original image source.
* If the width isn't known, then the image is reconstructed.
*/
public int getWidth() {
if (src != null) {
src.checkSecurity(null, false);
}
if ((availinfo & ImageObserver.WIDTH) == 0) {
reconstruct(ImageObserver.WIDTH);
}
return width;
}
/**
* Return the width of the original image source.
* If the width isn't known, then the ImageObserver object will be
* notified when the data is available.
*/
public synchronized int getWidth(ImageObserver iw) {
if (src != null) {
src.checkSecurity(null, false);
}
if ((availinfo & ImageObserver.WIDTH) == 0) {
addWatcher(iw, true);
if ((availinfo & ImageObserver.WIDTH) == 0) {
return -1;
}
}
return width;
}
/**
* Return the height of the original image source.
* If the height isn't known, then the image is reconstructed.
*/
public int getHeight() {
if (src != null) {
src.checkSecurity(null, false);
}
if ((availinfo & ImageObserver.HEIGHT) == 0) {
reconstruct(ImageObserver.HEIGHT);
}
return height;
}
/**
* Return the height of the original image source.
* If the height isn't known, then the ImageObserver object will be
* notified when the data is available.
*/
public synchronized int getHeight(ImageObserver iw) {
if (src != null) {
src.checkSecurity(null, false);
}
if ((availinfo & ImageObserver.HEIGHT) == 0) {
addWatcher(iw, true);
if ((availinfo & ImageObserver.HEIGHT) == 0) {
return -1;
}
}
return height;
}
/**
* Return a property of the image by name. Individual property names
* are defined by the various image formats. If a property is not
* defined for a particular image, then this method will return the
* UndefinedProperty object. If the properties for this image are
* not yet known, then this method will return null and the ImageObserver
* object will be notified later. The property name "comment" should
* be used to store an optional comment which can be presented to
* the user as a description of the image, its source, or its author.
*/
public Object getProperty(String name, ImageObserver observer) {
if (name == null) {
throw new NullPointerException("null property name is not allowed");
}
if (src != null) {
src.checkSecurity(null, false);
}
if (properties == null) {
addWatcher(observer, true);
if (properties == null) {
return null;
}
}
Object o = properties.get(name);
if (o == null) {
o = Image.UndefinedProperty;
}
return o;
}
public boolean hasError() {
if (src != null) {
src.checkSecurity(null, false);
}
return (availinfo & ImageObserver.ERROR) != 0;
}
public int check(ImageObserver iw) {
if (src != null) {
src.checkSecurity(null, false);
}
if ((availinfo & ImageObserver.ERROR) == 0 &&
((~availinfo) & (ImageObserver.WIDTH |
ImageObserver.HEIGHT |
ImageObserver.PROPERTIES)) != 0) {
addWatcher(iw, false);
}
return availinfo;
}
public void preload(ImageObserver iw) {
if (src != null) {
src.checkSecurity(null, false);
}
if ((availinfo & ImageObserver.ALLBITS) == 0) {
addWatcher(iw, true);
}
}
private synchronized void addWatcher(ImageObserver iw, boolean load) {
if ((availinfo & ImageObserver.ERROR) != 0) {
if (iw != null) {
iw.imageUpdate(this, ImageObserver.ERROR|ImageObserver.ABORT,
-1, -1, -1, -1);
}
return;
}
ImageRepresentation ir = getImageRep();
ir.addWatcher(iw);
if (load) {
ir.startProduction();
}
}
private synchronized void reconstruct(int flags) {
if ((flags & ~availinfo) != 0) {
if ((availinfo & ImageObserver.ERROR) != 0) {
return;
}
ImageRepresentation ir = getImageRep();
ir.startProduction();
while ((flags & ~availinfo) != 0) {
try {
wait();
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
return;
}
if ((availinfo & ImageObserver.ERROR) != 0) {
return;
}
}
}
}
synchronized void addInfo(int newinfo) {
availinfo |= newinfo;
notifyAll();
}
void setDimensions(int w, int h) {
width = w;
height = h;
addInfo(ImageObserver.WIDTH | ImageObserver.HEIGHT);
}
void setProperties(Hashtable props) {
if (props == null) {
props = new Hashtable();
}
properties = props;
addInfo(ImageObserver.PROPERTIES);
}
synchronized void infoDone(int status) {
if (status == ImageConsumer.IMAGEERROR ||
((~availinfo) & (ImageObserver.WIDTH |
ImageObserver.HEIGHT)) != 0) {
addInfo(ImageObserver.ERROR);
} else if ((availinfo & ImageObserver.PROPERTIES) == 0) {
setProperties(null);
}
}
public void flush() {
if (src != null) {
src.checkSecurity(null, false);
}
ImageRepresentation ir;
synchronized (this) {
availinfo &= ~ImageObserver.ERROR;
ir = imagerep;
imagerep = null;
}
if (ir != null) {
ir.abort();
}
if (src != null) {
src.flush();
}
}
protected ImageRepresentation makeImageRep() {
return new ImageRepresentation(this);
}
public synchronized ImageRepresentation getImageRep() {
if (src != null) {
src.checkSecurity(null, false);
}
if (imagerep == null) {
imagerep = makeImageRep();
}
return imagerep;
}
public Graphics getGraphics() {
throw new UnsupportedOperationException("getGraphics() not valid for images " +
"created with createImage(producer)");
}
// /* this method is needed by printing code */
// public ColorModel getColorModel() {
// ImageRepresentation imageRep = getImageRep();
// return imageRep.getColorModel();
// }
//
/* this method is needed by printing code */
public BufferedImage getBufferedImage() {
ImageRepresentation imageRep = getImageRep();
return imageRep.getBufferedImage();
}
//
// public void setAccelerationPriority(float priority) {
// super.setAccelerationPriority(priority);
// ImageRepresentation imageRep = getImageRep();
// imageRep.setAccelerationPriority(accelerationPriority);
// }
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,468 @@
/*
* Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* 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.
*/
package sun.awt.shell;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.*;
import java.util.List;
import java.util.concurrent.*;
import cli.System.IntPtr;
import cli.System.Drawing.Bitmap;
import cli.System.Drawing.SystemIcons;
import sun.security.action.LoadLibraryAction;
import static sun.awt.shell.Win32ShellFolder2.*;
import sun.awt.OSInfo;
// NOTE: This class supersedes Win32ShellFolderManager, which was removed
// from distribution after version 1.4.2.
/**
* @author Michael Martak
* @author Leif Samuelsson
* @author Kenneth Russell
* @since 1.4
*/
public class Win32ShellFolderManager2 extends ShellFolderManager {
public ShellFolder createShellFolder(File file) throws FileNotFoundException {
try {
return createShellFolder(getDesktop(), file);
} catch (InterruptedException e) {
throw new FileNotFoundException("Execution was interrupted");
}
}
@cli.System.Security.SecuritySafeCriticalAttribute.Annotation
static Win32ShellFolder2 createShellFolder(Win32ShellFolder2 parent, File file)
throws FileNotFoundException, InterruptedException {
cli.System.IntPtr pIDL = null;
try {
pIDL = parent.parseDisplayName(file.getCanonicalPath());
} catch (IOException ex) {
pIDL = null;
}
if (pIDL == null || cli.System.IntPtr.Zero.Equals(pIDL) ) {
// Shouldn't happen but watch for it anyway
throw new FileNotFoundException("File " + file.getAbsolutePath() + " not found");
}
try {
return createShellFolderFromRelativePIDL(parent, pIDL);
} finally {
Win32ShellFolder2.releasePIDL(pIDL);
}
}
@cli.System.Security.SecurityCriticalAttribute.Annotation
static Win32ShellFolder2 createShellFolderFromRelativePIDL(Win32ShellFolder2 parent, cli.System.IntPtr pIDL)
throws InterruptedException {
// Walk down this relative pIDL, creating new nodes for each of the entries
while (pIDL != null && !cli.System.IntPtr.Zero.Equals( pIDL ) ) {
cli.System.IntPtr curPIDL = Win32ShellFolder2.copyFirstPIDLEntry(pIDL);
if (curPIDL != null && !cli.System.IntPtr.Zero.Equals( curPIDL )) {
parent = new Win32ShellFolder2(parent, curPIDL);
pIDL = Win32ShellFolder2.getNextPIDLEntry(pIDL);
} else {
// The list is empty if the parent is Desktop and pIDL is a shortcut to Desktop
break;
}
}
return parent;
}
private static final int VIEW_LIST = 2;
private static final int VIEW_DETAILS = 3;
private static final int VIEW_PARENTFOLDER = 8;
private static final int VIEW_NEWFOLDER = 11;
private static final Image[] STANDARD_VIEW_BUTTONS = new Image[12];
@cli.System.Security.SecuritySafeCriticalAttribute.Annotation
private static Image getStandardViewButton(int iconIndex) {
Image result = STANDARD_VIEW_BUTTONS[iconIndex];
if (result != null) {
return result;
}
Bitmap bitmap = Win32ShellFolder2.getStandardViewButton0(iconIndex);
if( bitmap != null ) {
result = new BufferedImage(bitmap);
STANDARD_VIEW_BUTTONS[iconIndex] = result;
}
return result;
}
// Special folders
private static Win32ShellFolder2 desktop;
private static Win32ShellFolder2 drives;
private static Win32ShellFolder2 recent;
private static Win32ShellFolder2 network;
private static Win32ShellFolder2 personal;
static Win32ShellFolder2 getDesktop() {
if (desktop == null) {
try {
desktop = new Win32ShellFolder2(DESKTOP);
} catch (IOException e) {
// Ignore error
} catch (InterruptedException e) {
// Ignore error
}
}
return desktop;
}
static Win32ShellFolder2 getDrives() {
if (drives == null) {
try {
drives = new Win32ShellFolder2(DRIVES);
} catch (IOException e) {
// Ignore error
} catch (InterruptedException e) {
// Ignore error
}
}
return drives;
}
@cli.System.Security.SecuritySafeCriticalAttribute.Annotation
static Win32ShellFolder2 getRecent() {
if (recent == null) {
try {
String path = Win32ShellFolder2.getFileSystemPath(RECENT);
if (path != null) {
recent = createShellFolder(getDesktop(), new File(path));
}
} catch (InterruptedException e) {
// Ignore error
} catch (IOException e) {
// Ignore error
}
}
return recent;
}
static Win32ShellFolder2 getNetwork() {
if (network == null) {
try {
network = new Win32ShellFolder2(NETWORK);
} catch (IOException e) {
// Ignore error
} catch (InterruptedException e) {
// Ignore error
}
}
return network;
}
@cli.System.Security.SecuritySafeCriticalAttribute.Annotation
static Win32ShellFolder2 getPersonal() {
if (personal == null) {
try {
String path = Win32ShellFolder2.getFileSystemPath(PERSONAL);
if (path != null) {
Win32ShellFolder2 desktop = getDesktop();
personal = desktop.getChildByPath(path);
if (personal == null) {
personal = createShellFolder(getDesktop(), new File(path));
}
if (personal != null) {
personal.setIsPersonal();
}
}
} catch (InterruptedException e) {
// Ignore error
} catch (IOException e) {
// Ignore error
}
}
return personal;
}
private static File[] roots;
/**
* @param key a <code>String</code>
* "fileChooserDefaultFolder":
* Returns a <code>File</code> - the default shellfolder for a new filechooser
* "roots":
* Returns a <code>File[]</code> - containing the root(s) of the displayable hierarchy
* "fileChooserComboBoxFolders":
* Returns a <code>File[]</code> - an array of shellfolders representing the list to
* show by default in the file chooser's combobox
* "fileChooserShortcutPanelFolders":
* Returns a <code>File[]</code> - an array of shellfolders representing well-known
* folders, such as Desktop, Documents, History, Network, Home, etc.
* This is used in the shortcut panel of the filechooser on Windows 2000
* and Windows Me.
* "fileChooserIcon <icon>":
* Returns an <code>Image</code> - icon can be ListView, DetailsView, UpFolder, NewFolder or
* ViewMenu (Windows only).
* "optionPaneIcon iconName":
* Returns an <code>Image</code> - icon from the system icon list
*
* @return An Object matching the key string.
*/
public Object get(String key) {
if (key.equals("fileChooserDefaultFolder")) {
File file = getPersonal();
if (file == null) {
file = getDesktop();
}
return file;
} else if (key.equals("roots")) {
// Should be "History" and "Desktop" ?
if (roots == null) {
File desktop = getDesktop();
if (desktop != null) {
roots = new File[] { desktop };
} else {
roots = (File[])super.get(key);
}
}
return roots;
} else if (key.equals("fileChooserComboBoxFolders")) {
Win32ShellFolder2 desktop = getDesktop();
if (desktop != null) {
ArrayList<File> folders = new ArrayList<File>();
Win32ShellFolder2 drives = getDrives();
Win32ShellFolder2 recentFolder = getRecent();
if (recentFolder != null && OSInfo.getWindowsVersion().compareTo(OSInfo.WINDOWS_2000) >= 0) {
folders.add(recentFolder);
}
folders.add(desktop);
// Add all second level folders
File[] secondLevelFolders = desktop.listFiles();
Arrays.sort(secondLevelFolders);
for (File secondLevelFolder : secondLevelFolders) {
Win32ShellFolder2 folder = (Win32ShellFolder2) secondLevelFolder;
if (!folder.isFileSystem() || (folder.isDirectory() && !folder.isLink()) ) {
folders.add(folder);
// Add third level for "My Computer"
if (folder.equals(drives)) {
File[] thirdLevelFolders = folder.listFiles();
if (thirdLevelFolders != null && thirdLevelFolders.length > 0) {
List<File> thirdLevelFoldersList = Arrays.asList(thirdLevelFolders);
folder.sortChildren(thirdLevelFoldersList);
folders.addAll(thirdLevelFoldersList);
}
}
}
}
return folders.toArray(new File[folders.size()]);
} else {
return super.get(key);
}
} else if (key.equals("fileChooserShortcutPanelFolders")) {
Toolkit toolkit = Toolkit.getDefaultToolkit();
ArrayList<File> folders = new ArrayList<File>();
int i = 0;
Object value;
do {
value = toolkit.getDesktopProperty("win.comdlg.placesBarPlace" + i++);
try {
if (value instanceof Integer) {
// A CSIDL
folders.add(new Win32ShellFolder2((Integer)value));
} else if (value instanceof String) {
// A path
folders.add(createShellFolder(new File((String)value)));
}
} catch (IOException e) {
// Skip this value
} catch (InterruptedException e) {
// Return empty result
return new File[0];
}
} while (value != null);
if (folders.size() == 0) {
// Use default list of places
for (File f : new File[] {
getRecent(), getDesktop(), getPersonal(), getDrives(), getNetwork()
}) {
if (f != null) {
folders.add(f);
}
}
}
return folders.toArray(new File[folders.size()]);
} else if (key.startsWith("fileChooserIcon ")) {
String name = key.substring(key.indexOf(" ") + 1);
int iconIndex;
if (name.equals("ListView") || name.equals("ViewMenu")) {
iconIndex = VIEW_LIST;
} else if (name.equals("DetailsView")) {
iconIndex = VIEW_DETAILS;
} else if (name.equals("UpFolder")) {
iconIndex = VIEW_PARENTFOLDER;
} else if (name.equals("NewFolder")) {
iconIndex = VIEW_NEWFOLDER;
} else {
return null;
}
return getStandardViewButton(iconIndex);
} else if (key.startsWith("optionPaneIcon ")) {
cli.System.Drawing.Icon icon;
if (key == "optionPaneIcon Error") {
icon = SystemIcons.get_Error();
} else if (key == "optionPaneIcon Information") {
icon = SystemIcons.get_Information();
} else if (key == "optionPaneIcon Question") {
icon = SystemIcons.get_Question();
} else if (key == "optionPaneIcon Warning") {
icon = SystemIcons.get_Warning();
} else {
return null;
}
return new BufferedImage(icon.ToBitmap());
} else if (key.startsWith("shell32Icon ") || key.startsWith("shell32LargeIcon ")) {
String name = key.substring(key.indexOf(" ") + 1);
try {
int i = Integer.parseInt(name);
if (i >= 0) {
return Win32ShellFolder2.getShell32Icon(i, key.startsWith("shell32LargeIcon "));
}
} catch (NumberFormatException ex) {
}
}
return null;
}
/**
* Does <code>dir</code> represent a "computer" such as a node on the network, or
* "My Computer" on the desktop.
*/
public boolean isComputerNode(final File dir) {
if (dir != null && dir == getDrives()) {
return true;
} else {
String path = AccessController.doPrivileged(new PrivilegedAction<String>() {
public String run() {
return dir.getAbsolutePath();
}
});
return (path.startsWith("\\\\") && path.indexOf("\\", 2) < 0); //Network path
}
}
public boolean isFileSystemRoot(File dir) {
//Note: Removable drives don't "exist" but are listed in "My Computer"
if (dir != null) {
Win32ShellFolder2 drives = getDrives();
if (dir instanceof Win32ShellFolder2) {
Win32ShellFolder2 sf = (Win32ShellFolder2)dir;
if (sf.isFileSystem()) {
if (sf.parent != null) {
return sf.parent.equals(drives);
}
// else fall through ...
} else {
return false;
}
}
String path = dir.getPath();
if (path.length() != 3 || path.charAt(1) != ':') {
return false;
}
File[] files = drives.listFiles();
return files != null && Arrays.asList(files).contains(dir);
}
return false;
}
private static List topFolderList = null;
static int compareShellFolders(Win32ShellFolder2 sf1, Win32ShellFolder2 sf2) {
boolean special1 = sf1.isSpecial();
boolean special2 = sf2.isSpecial();
if (special1 || special2) {
if (topFolderList == null) {
ArrayList tmpTopFolderList = new ArrayList();
tmpTopFolderList.add(Win32ShellFolderManager2.getPersonal());
tmpTopFolderList.add(Win32ShellFolderManager2.getDesktop());
tmpTopFolderList.add(Win32ShellFolderManager2.getDrives());
tmpTopFolderList.add(Win32ShellFolderManager2.getNetwork());
topFolderList = tmpTopFolderList;
}
int i1 = topFolderList.indexOf(sf1);
int i2 = topFolderList.indexOf(sf2);
if (i1 >= 0 && i2 >= 0) {
return (i1 - i2);
} else if (i1 >= 0) {
return -1;
} else if (i2 >= 0) {
return 1;
}
}
// Non-file shellfolders sort before files
if (special1 && !special2) {
return -1;
} else if (special2 && !special1) {
return 1;
}
return compareNames(sf1.getAbsolutePath(), sf2.getAbsolutePath());
}
static int compareNames(String name1, String name2) {
// First ignore case when comparing
int diff = name1.compareToIgnoreCase(name2);
if (diff != 0) {
return diff;
} else {
// May differ in case (e.g. "mail" vs. "Mail")
// We need this test for consistent sorting
return name1.compareTo(name2);
}
}
}

View File

@@ -0,0 +1,126 @@
/*
Copyright (C) 2009 Volker Berlin (i-net software)
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
Jeroen Frijters
jeroen@frijters.net
*/
package sun.awt.windows;
import ikvm.awt.IkvmToolkit;
import java.awt.Graphics;
import java.awt.HeadlessException;
import java.awt.Toolkit;
import java.awt.image.BufferedImage;
import java.awt.print.PageFormat;
import java.awt.print.Pageable;
import java.awt.print.Paper;
import java.awt.print.Printable;
import java.awt.print.PrinterException;
import java.awt.print.PrinterJob;
import javax.print.PrintService;
import javax.print.attribute.PrintRequestAttributeSet;
import cli.System.Drawing.Printing.*;
import sun.print.PeekGraphics;
import sun.print.PrintPeer;
import sun.print.RasterPrinterJob;
import sun.print.Win32PrintService;
import ikvm.internal.NotYetImplementedError;
/**
* @author Volker Berlin
*/
public class WPrinterJob extends RasterPrinterJob{
@Override
protected void abortDoc(){
throw new NotYetImplementedError();
}
@Override
protected void endDoc() throws PrinterException{
throw new NotYetImplementedError();
}
@Override
protected void endPage(PageFormat format, Printable painter, int index) throws PrinterException{
throw new NotYetImplementedError();
}
@Override
protected double getPhysicalPageHeight(Paper p){
throw new NotYetImplementedError();
}
@Override
protected double getPhysicalPageWidth(Paper p){
throw new NotYetImplementedError();
}
@Override
protected double getPhysicalPrintableHeight(Paper p){
throw new NotYetImplementedError();
}
@Override
protected double getPhysicalPrintableWidth(Paper p){
throw new NotYetImplementedError();
}
@Override
protected double getPhysicalPrintableX(Paper p){
throw new NotYetImplementedError();
}
@Override
protected double getPhysicalPrintableY(Paper p){
throw new NotYetImplementedError();
}
@Override
protected double getXRes(){
throw new NotYetImplementedError();
}
@Override
protected double getYRes(){
throw new NotYetImplementedError();
}
@Override
protected void printBand(byte[] data, int x, int y, int width, int height) throws PrinterException{
throw new NotYetImplementedError();
}
@Override
protected void startDoc() throws PrinterException{
throw new NotYetImplementedError();
}
@Override
protected void startPage(PageFormat format, Printable painter, int index, boolean paperChanged)
throws PrinterException{
throw new NotYetImplementedError();
}
}

View File

@@ -0,0 +1,152 @@
/*
Copyright (C) 2009, 2011 Volker Berlin (i-net software)
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
Jeroen Frijters
jeroen@frijters.net
*/
package sun.font;
import java.awt.font.FontRenderContext;
import java.awt.geom.AffineTransform;
import java.util.Locale;
import cli.System.Drawing.Font;
import ikvm.internal.NotYetImplementedError;
/**
*
*/
public class CompositeFont extends Font2D{
private final PhysicalFont delegate;
public CompositeFont(PhysicalFont physicalFont, CompositeFont dialog2d) {
delegate = physicalFont;
}
public CompositeFont(Font2D font2d){
delegate = (PhysicalFont)font2d;
}
public int getNumSlots() {
throw new NotYetImplementedError();
}
public PhysicalFont getSlotFont(int slot) {
if( slot == 0){
return delegate;
}
throw new NotYetImplementedError();
}
public boolean isStdComposite() {
throw new NotYetImplementedError();
}
@Override
public int getStyle(){
return delegate.getStyle();
}
@Override
public Font createNetFont(java.awt.Font font){
return delegate.createNetFont(font);
}
public FontStrike getStrike(java.awt.Font font, AffineTransform devTx,
int aa, int fm) {
return delegate.getStrike(font, devTx, aa, fm);
}
public FontStrike getStrike(java.awt.Font font, FontRenderContext frc) {
return delegate.getStrike(font, frc);
}
public void removeFromCache(FontStrikeDesc desc) {
delegate.removeFromCache(desc);
}
public void getFontMetrics(java.awt.Font font, AffineTransform identityTx,
Object antiAliasingHint, Object fractionalMetricsHint,
float[] metrics) {
delegate.getFontMetrics(font, identityTx, antiAliasingHint,
fractionalMetricsHint, metrics);
}
public void getStyleMetrics(float pointSize, float[] metrics, int offset) {
delegate.getStyleMetrics(pointSize, metrics, offset);
}
public void getFontMetrics(java.awt.Font font, FontRenderContext frc,
float[] metrics) {
delegate.getFontMetrics(font, frc, metrics);
}
public boolean useAAForPtSize(int ptsize) {
return delegate.useAAForPtSize(ptsize);
}
public boolean hasSupplementaryChars() {
return delegate.hasSupplementaryChars();
}
public String getPostscriptName() {
return delegate.getPostscriptName();
}
public String getFontName(Locale l) {
return delegate.getFontName(l);
}
public String getFamilyName(Locale l) {
return delegate.getFamilyName(l);
}
public int getNumGlyphs() {
return delegate.getNumGlyphs();
}
public int charToGlyph(int wchar) {
return delegate.charToGlyph(wchar);
}
public int getMissingGlyphCode() {
return delegate.getMissingGlyphCode();
}
public boolean canDisplay(char c) {
return delegate.canDisplay(c);
}
public boolean canDisplay(int cp) {
return delegate.canDisplay(cp);
}
public byte getBaselineFor(char c) {
return delegate.getBaselineFor(c);
}
public float getItalicAngle(java.awt.Font font, AffineTransform at,
Object aaHint, Object fmHint) {
return delegate.getItalicAngle(font, at, aaHint, fmHint);
}
}

View File

@@ -0,0 +1,221 @@
/*
Copyright (C) 2009 Volker Berlin (i-net software)
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
Jeroen Frijters
jeroen@frijters.net
*/
package sun.font;
import java.awt.Font;
import java.awt.font.FontRenderContext;
import java.awt.geom.AffineTransform;
import java.util.Locale;
import sun.awt.SunHints;
/**
*
*/
public abstract class Font2D{
public Font2DHandle handle = new Font2DHandle(this);
/* SunGraphics2D has font, tx, aa and fm. From this info
* can get a Strike object from the cache, creating it if necessary.
* This code is designed for multi-threaded access.
* For that reason it creates a local FontStrikeDesc rather than filling
* in a shared one. Up to two AffineTransforms and one FontStrikeDesc will
* be created by every lookup. This appears to perform more than
* adequately. But it may make sense to expose FontStrikeDesc
* as a parameter so a caller can use its own.
* In such a case if a FontStrikeDesc is stored as a key then
* we would need to use a private copy.
*
* Note that this code doesn't prevent two threads from creating
* two different FontStrike instances and having one of the threads
* overwrite the other in the map. This is likely to be a rare
* occurrence and the only consequence is that these callers will have
* different instances of the strike, and there'd be some duplication of
* population of the strikes. However since users of these strikes are
* transient, then the one that was overwritten would soon be freed.
* If there is any problem then a small synchronized block would be
* required with its attendant consequences for MP scalability.
*/
public FontStrike getStrike(Font font, AffineTransform devTx, int aa, int fm){
return getStrike(font, new FontRenderContext(devTx, aa == SunHints.INTVAL_TEXT_ANTIALIAS_ON,
fm == SunHints.INTVAL_FRACTIONALMETRICS_ON));
}
public FontStrike getStrike(Font font, FontRenderContext frc) {
// TODO Auto-generated method stub
return null;
}
public void removeFromCache(FontStrikeDesc desc){
// TODO Auto-generated method stub
}
/**
* The length of the metrics array must be >= 8. This method will
* store the following elements in that array before returning:
* metrics[0]: ascent
* metrics[1]: descent
* metrics[2]: leading
* metrics[3]: max advance
* metrics[4]: strikethrough offset
* metrics[5]: strikethrough thickness
* metrics[6]: underline offset
* metrics[7]: underline thickness
*/
public void getFontMetrics(Font font, AffineTransform identityTx, Object antiAliasingHint,
Object fractionalMetricsHint, float[] metrics){
FontRenderContext frc = new FontRenderContext(identityTx, antiAliasingHint, fractionalMetricsHint);
StrikeMetrics strikeMetrics = getStrike(font, frc).getFontMetrics();
metrics[0] = strikeMetrics.getAscent();
metrics[1] = strikeMetrics.getDescent();
metrics[2] = strikeMetrics.getLeading();
metrics[3] = strikeMetrics.getMaxAdvance();
getStyleMetrics(font.getSize2D(), metrics, 4);
}
/**
* The length of the metrics array must be >= offset+4, and offset must be
* >= 0. Typically offset is 4. This method will
* store the following elements in that array before returning:
* metrics[off+0]: strikethrough offset
* metrics[off+1]: strikethrough thickness
* metrics[off+2]: underline offset
* metrics[off+3]: underline thickness
*
* Note that this implementation simply returns default values;
* subclasses can override this method to provide more accurate values.
*/
public void getStyleMetrics(float pointSize, float[] metrics, int offset) {
metrics[offset] = -metrics[0] / 2.5f;
metrics[offset+1] = pointSize / 12;
metrics[offset+2] = metrics[offset+1] / 1.5f;
metrics[offset+3] = metrics[offset+1];
}
/**
* The length of the metrics array must be >= 4. This method will
* store the following elements in that array before returning:
* metrics[0]: ascent
* metrics[1]: descent
* metrics[2]: leading
* metrics[3]: max advance
*/
public void getFontMetrics(Font font, FontRenderContext frc,
float metrics[]) {
StrikeMetrics strikeMetrics = getStrike(font, frc).getFontMetrics();
metrics[0] = strikeMetrics.getAscent();
metrics[1] = strikeMetrics.getDescent();
metrics[2] = strikeMetrics.getLeading();
metrics[3] = strikeMetrics.getMaxAdvance();
}
/*
* All the important subclasses override this which is principally for
* the TrueType 'gasp' table.
*/
public boolean useAAForPtSize(int ptsize) {
return true;
}
public boolean hasSupplementaryChars() {
return false;
}
/* The following methods implement public methods on java.awt.Font */
public String getPostscriptName(){
// TODO Auto-generated method stub
return null;
}
public String getFontName(Locale l){
// TODO Auto-generated method stub
return null;
}
public String getFamilyName(Locale l){
// TODO Auto-generated method stub
return null;
}
public int getNumGlyphs(){
// TODO Auto-generated method stub
return 0;
}
public int charToGlyph(int wchar) {
return wchar;
}
public int getMissingGlyphCode(){
// TODO Auto-generated method stub
return 0;
}
public boolean canDisplay(char c){
//HACK There is no equivalent in C# http://msdn2.microsoft.com/en-us/library/sf4dhbw8(VS.80).aspx
return true;
}
public boolean canDisplay(int cp){
//HACK There is no equivalent in C# http://msdn2.microsoft.com/en-us/library/sf4dhbw8(VS.80).aspx
return true;
}
public byte getBaselineFor(char c) {
return Font.ROMAN_BASELINE;
}
public float getItalicAngle(Font font, AffineTransform at,
Object aaHint, Object fmHint) {
/* hardwire psz=12 as that's typical and AA vs non-AA for 'gasp' mode
* isn't important for the caret slope of this rarely used API.
*/
int aa = FontStrikeDesc.getAAHintIntVal(aaHint, this, 12);
int fm = FontStrikeDesc.getFMHintIntVal(fmHint);
FontStrike strike = getStrike(font, at, aa, fm);
StrikeMetrics metrics = strike.getFontMetrics();
if (metrics.ascentY == 0 || metrics.ascentX == 0) {
return 0f;
} else {
/* ascent is "up" from the baseline so its typically
* a negative value, so we need to compensate
*/
return metrics.ascentX/-metrics.ascentY;
}
}
/** Returns the "real" style of this Font2D. Eg the font face
* Lucida Sans Bold" has a real style of Font.BOLD, even though
* it may be able to used to simulate bold italic
*/
public abstract int getStyle();
public abstract cli.System.Drawing.Font createNetFont(Font font);
}

View File

@@ -0,0 +1,415 @@
/*
* Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
* Copyright (C) 2009 - 2011 Volker Berlin (i-net software)
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* 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.
*/
package sun.font;
import java.awt.Font;
import java.lang.reflect.Method;
import java.util.Locale;
import java.util.concurrent.ConcurrentHashMap;
import javax.swing.plaf.FontUIResource;
import cli.System.Drawing.FontFamily;
import ikvm.internal.NotYetImplementedError;
/*
* Interface between Java Fonts (java.awt.Font) and the underlying
* font files/native font resources and the Java and native font scalers.
*/
public final class FontManager {
public static final int NO_FALLBACK = 0;
public static final int PHYSICAL_FALLBACK = 1;
public static final int LOGICAL_FALLBACK = 2;
/* deprecated, unsupported hack - actually invokes a bug! */
private static boolean usePlatformFontMetrics = false;
private static ConcurrentHashMap<String, Font2D> fontNameCache = new ConcurrentHashMap<String, Font2D>();
private static final Method getFont2D;
static{
try{
getFont2D = Font.class.getDeclaredMethod("getFont2D");
getFont2D.setAccessible(true);
}catch(NoSuchMethodException ex){
NoClassDefFoundError error = new NoClassDefFoundError(ex.toString());
error.initCause(ex);
throw error;
}
}
/* Revise the implementation to in fact mean "font is a composite font.
* This ensures that Swing components will always benefit from the
* fall back fonts
*/
public static boolean fontSupportsDefaultEncoding(Font font) {
// In Java the font must be a instanceof CompositeFont
// because .NET fonts are all already Composite Fonts (I think) that we can return true
// and does not need to implements CompositeFont
return true;
}
/**
* This method is provided for internal and exclusive use by Swing.
*
* It may be used in conjunction with fontSupportsDefaultEncoding(Font)
* In the event that a desktop properties font doesn't directly
* support the default encoding, (ie because the host OS supports
* adding support for the current locale automatically for native apps),
* then Swing calls this method to get a font which uses the specified
* font for the code points it covers, but also supports this locale
* just as the standard composite fonts do.
* Note: this will over-ride any setting where an application
* specifies it prefers locale specific composite fonts.
* The logic for this, is that this method is used only where the user or
* application has specified that the native L&F be used, and that
* we should honour that request to use the same font as native apps use.
*
* The behaviour of this method is to construct a new composite
* Font object that uses the specified physical font as its first
* component, and adds all the components of "dialog" as fall back
* components.
* The method currently assumes that only the size and style attributes
* are set on the specified font. It doesn't copy the font transform or
* other attributes because they aren't set on a font created from
* the desktop. This will need to be fixed if use is broadened.
*
* Operations such as Font.deriveFont will work properly on the
* font returned by this method for deriving a different point size.
* Additionally it tries to support a different style by calling
* getNewComposite() below. That also supports replacing slot zero
* with a different physical font but that is expected to be "rare".
* Deriving with a different style is needed because its been shown
* that some applications try to do this for Swing FontUIResources.
* Also operations such as new Font(font.getFontName(..), Font.PLAIN, 14);
* will NOT yield the same result, as the new underlying CompositeFont
* cannot be "looked up" in the font registry.
* This returns a FontUIResource as that is the Font sub-class needed
* by Swing.
* Suggested usage is something like :
* FontUIResource fuir;
* Font desktopFont = getDesktopFont(..);
* // NOTE even if fontSupportsDefaultEncoding returns true because
* // you get Tahoma and are running in an English locale, you may
* // still want to just call getCompositeFontUIResource() anyway
* // as only then will you get fallback fonts - eg for CJK.
* if (FontManager.fontSupportsDefaultEncoding(desktopFont)) {
* fuir = new FontUIResource(..);
* } else {
* fuir = FontManager.getCompositeFontUIResource(desktopFont);
* }
* return fuir;
*/
public static FontUIResource getCompositeFontUIResource(Font font) {
throw new NotYetImplementedError();
}
public static Font2D getNewComposite(String family, int style, Font2D handle) {
throw new NotYetImplementedError();
}
/*
* return String representation of style prepended with "."
* This is useful for performance to avoid unnecessary string operations.
*/
private static String dotStyleStr(int num) {
switch(num){
case Font.BOLD:
return ".bold";
case Font.ITALIC:
return ".italic";
case Font.ITALIC | Font.BOLD:
return ".bolditalic";
default:
return ".plain";
}
}
/*
* The client supplies a name and a style.
* The name could be a family name, or a full name.
* A font may exist with the specified style, or it may
* exist only in some other style. For non-native fonts the scaler
* may be able to emulate the required style.
*/
public static Font2D findFont2D(String name, int style, int fallback){
String lowerCaseName = name.toLowerCase(Locale.ENGLISH);
String mapName = lowerCaseName + dotStyleStr(style);
Font2D font2D = fontNameCache.get(mapName);
if(font2D != null){
return font2D;
}
font2D = new PhysicalFont(name,style);
fontNameCache.put(mapName, font2D);
return font2D;
}
/**
* Create a new Font2D without caching. This is used from createFont
*
* @param family
* .NET FontFamily
* @param style
* the style
* @return a Font2D
*/
public static Font2D createFont2D( FontFamily family, int style ) {
return new PhysicalFont( family, style );
}
/* This method can be more efficient as it will only need to
* do the lookup once, and subsequent calls on the java.awt.Font
* instance can utilise the cached Font2D on that object.
* Its unfortunate it needs to be a native method, but the font2D
* variable has to be private.
*/
public static Font2D getFont2D(Font font){
try{
return (Font2D)getFont2D.invoke(font);
}catch(Exception ex){
throw new RuntimeException(ex);
}
}
/* Stuff below was in NativeFontWrapper and needed a new home */
/*
* Workaround for apps which are dependent on a font metrics bug
* in JDK 1.1. This is an unsupported win32 private setting.
*/
public static boolean usePlatformFontMetrics() {
return usePlatformFontMetrics;
}
/* This method doesn't check if alternates are selected in this app
* context. Its used by the FontMetrics caching code which in such
* a case cannot retrieve a cached metrics solely on the basis of
* the Font.equals() method since it needs to also check if the Font2D
* is the same.
* We also use non-standard composites for Swing native L&F fonts on
* Windows. In that case the policy is that the metrics reported are
* based solely on the physical font in the first slot which is the
* visible java.awt.Font. So in that case the metrics cache which tests
* the Font does what we want. In the near future when we expand the GTK
* logical font definitions we may need to revisit this if GTK reports
* combined metrics instead. For now though this test can be simple.
*/
static boolean maybeUsingAlternateCompositeFonts() {
// TODO Auto-generated method stub
return false;
}
public static synchronized void preferLocaleFonts() {
// TODO Auto-generated method stub
}
public static synchronized void preferProportionalFonts() {
// TODO Auto-generated method stub
}
public static boolean registerFont(Font font) {
/* This method should not be called with "null".
* It is the caller's responsibility to ensure that.
*/
// TODO Auto-generated method stub
return false;
}
/* This is called by Swing passing in a fontconfig family name
* such as "sans". In return Swing gets a FontUIResource instance
* that has queried fontconfig to resolve the font(s) used for this.
* Fontconfig will if asked return a list of fonts to give the largest
* possible code point coverage.
* For now we use only the first font returned by fontconfig, and
* back it up with the most closely matching JDK logical font.
* Essentially this means pre-pending what we return now with fontconfig's
* preferred physical font. This could lead to some duplication in cases,
* if we already included that font later. We probably should remove such
* duplicates, but it is not a significant problem. It can be addressed
* later as part of creating a Composite which uses more of the
* same fonts as fontconfig. At that time we also should pay more
* attention to the special rendering instructions fontconfig returns,
* such as whether we should prefer embedded bitmaps over antialiasing.
* There's no way to express that via a Font at present.
*/
public static FontUIResource getFontConfigFUIR( String fcFamily, int style, int size ) {
return new FontUIResource( fcFamily, style, size );
}
/* The following fields and methods which relate to layout
* perhaps belong in some other class but FontManager is already
* widely used as an entry point for other JDK code that needs
* access to the font system internals.
*/
/**
* Referenced by code in the JDK which wants to test for the
* minimum char code for which layout may be required.
* Note that even basic latin text can benefit from ligatures,
* eg "ffi" but we presently apply those only if explicitly
* requested with TextAttribute.LIGATURES_ON.
* The value here indicates the lowest char code for which failing
* to invoke layout would prevent acceptable rendering.
*/
public static final int MIN_LAYOUT_CHARCODE = 0x0300;
/**
* Referenced by code in the JDK which wants to test for the
* maximum char code for which layout may be required.
* Note this does not account for supplementary characters
* where the caller interprets 'layout' to mean any case where
* one 'char' (ie the java type char) does not map to one glyph
*/
public static final int MAX_LAYOUT_CHARCODE = 0x206F;
/* If the character code falls into any of a number of unicode ranges
* where we know that simple left->right layout mapping chars to glyphs
* 1:1 and accumulating advances is going to produce incorrect results,
* we want to know this so the caller can use a more intelligent layout
* approach. A caller who cares about optimum performance may want to
* check the first case and skip the method call if its in that range.
* Although there's a lot of tests in here, knowing you can skip
* CTL saves a great deal more. The rest of the checks are ordered
* so that rather than checking explicitly if (>= start & <= end)
* which would mean all ranges would need to be checked so be sure
* CTL is not needed, the method returns as soon as it recognises
* the code point is outside of a CTL ranges.
* NOTE: Since this method accepts an 'int' it is asssumed to properly
* represent a CHARACTER. ie it assumes the caller has already
* converted surrogate pairs into supplementary characters, and so
* can handle this case and doesn't need to be told such a case is
* 'complex'.
*/
static boolean isComplexCharCode(int code) {
if (code < MIN_LAYOUT_CHARCODE || code > MAX_LAYOUT_CHARCODE) {
return false;
}
else if (code <= 0x036f) {
// Trigger layout for combining diacriticals 0x0300->0x036f
return true;
}
else if (code < 0x0590) {
// No automatic layout for Greek, Cyrillic, Armenian.
return false;
}
else if (code <= 0x06ff) {
// Hebrew 0590 - 05ff
// Arabic 0600 - 06ff
return true;
}
else if (code < 0x0900) {
return false; // Syriac and Thaana
}
else if (code <= 0x0e7f) {
// if Indic, assume shaping for conjuncts, reordering:
// 0900 - 097F Devanagari
// 0980 - 09FF Bengali
// 0A00 - 0A7F Gurmukhi
// 0A80 - 0AFF Gujarati
// 0B00 - 0B7F Oriya
// 0B80 - 0BFF Tamil
// 0C00 - 0C7F Telugu
// 0C80 - 0CFF Kannada
// 0D00 - 0D7F Malayalam
// 0D80 - 0DFF Sinhala
// 0E00 - 0E7F if Thai, assume shaping for vowel, tone marks
return true;
}
else if (code < 0x1780) {
return false;
}
else if (code <= 0x17ff) { // 1780 - 17FF Khmer
return true;
}
else if (code < 0x200c) {
return false;
}
else if (code <= 0x200d) { // zwj or zwnj
return true;
}
else if (code >= 0x202a && code <= 0x202e) { // directional control
return true;
}
else if (code >= 0x206a && code <= 0x206f) { // directional control
return true;
}
return false;
}
/* This is almost the same as the method above, except it takes a
* char which means it may include undecoded surrogate pairs.
* The distinction is made so that code which needs to identify all
* cases in which we do not have a simple mapping from
* char->unicode character->glyph can be be identified.
* For example measurement cannot simply sum advances of 'chars',
* the caret in editable text cannot advance one 'char' at a time, etc.
* These callers really are asking for more than whether 'layout'
* needs to be run, they need to know if they can assume 1->1
* char->glyph mapping.
*/
static boolean isNonSimpleChar(char ch) {
return
isComplexCharCode(ch) ||
(ch >= CharToGlyphMapper.HI_SURROGATE_START &&
ch <= CharToGlyphMapper.LO_SURROGATE_END);
}
/**
* If there is anything in the text which triggers a case
* where char->glyph does not map 1:1 in straightforward
* left->right ordering, then this method returns true.
* Scripts which might require it but are not treated as such
* due to JDK implementations will not return true.
* ie a 'true' return is an indication of the treatment by
* the implementation.
* Whether supplementary characters should be considered is dependent
* on the needs of the caller. Since this method accepts the 'char' type
* then such chars are always represented by a pair. From a rendering
* perspective these will all (in the cases I know of) still be one
* unicode character -> one glyph. But if a caller is using this to
* discover any case where it cannot make naive assumptions about
* the number of chars, and how to index through them, then it may
* need the option to have a 'true' return in such a case.
*/
public static boolean isComplexText(char [] chs, int start, int limit) {
for (int i = start; i < limit; i++) {
if (chs[i] < MIN_LAYOUT_CHARCODE) {
continue;
}
else if (isNonSimpleChar(chs[i])) {
return true;
}
}
return false;
}
}

View File

@@ -0,0 +1,76 @@
/*
Copyright (C) 2009, 2011 Volker Berlin (i-net software)
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
Jeroen Frijters
jeroen@frijters.net
*/
package sun.font;
import java.awt.Font;
import java.awt.font.FontRenderContext;
/**
*
*/
public class GlyphLayout{
private static GlyphLayout glyphLayout = new GlyphLayout();
/**
* Return a new instance of GlyphLayout, using the provided layout engine factory.
* If null, the system layout engine factory will be used.
*/
public static GlyphLayout get(Object lef) {
return glyphLayout; //current this class has no state
}
/**
* Return the old instance of GlyphLayout when you are done. This enables reuse
* of GlyphLayout objects.
*/
public static void done(GlyphLayout gl) {
}
/**
* Create a glyph vector.
* @param font the font to use
* @param frc the font render context
* @param text the text, including optional context before start and after start + count
* @param offset the start of the text to lay out
* @param count the length of the text to lay out
* @param flags bidi and context flags {@see #java.awt.Font}
* @param result a StandardGlyphVector to modify, can be null
* @return the layed out glyphvector, if result was passed in, it is returned
*/
public StandardGlyphVector layout(Font font, FontRenderContext frc,
char[] text, int offset, int count,
int flags, StandardGlyphVector result)
{
if (text == null || offset < 0 || count < 0 || (count > text.length - offset)) {
throw new IllegalArgumentException();
}
return new StandardGlyphVector(font, text, offset, count, frc);
}
}

Some files were not shown because too many files have changed in this diff Show More