Update ooo320-m1
[ooovba.git] / canvas / source / java / TextLayout.java
blob89c4ab57042cfc7572ee81985c312409010168ed
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: TextLayout.java,v $
10 * $Revision: 1.6 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // Canvas
32 import com.sun.star.rendering.*;
34 public class TextLayout
35 extends com.sun.star.lib.uno.helper.ComponentBase
36 implements com.sun.star.lang.XServiceInfo,
37 com.sun.star.rendering.XTextLayout
39 private double[] advancements;
40 private StringContext text;
41 private byte direction;
42 private CanvasBase associatedCanvas;
43 private CanvasFont font;
45 //----------------------------------------------------------------------------------
47 public TextLayout( StringContext aText,
48 byte nDirection,
49 long nRandomSeed,
50 CanvasFont _font,
51 CanvasBase _canvas )
53 text = aText;
54 direction = nDirection;
55 associatedCanvas = _canvas;
56 font = _font;
60 // XTextLayout implementation
61 // ==========================
64 public XPolyPolygon2D[] queryTextShapes( )
66 // TODO
67 return null;
70 public com.sun.star.geometry.RealRectangle2D[] queryInkMeasures( )
72 // TODO
73 return null;
76 public com.sun.star.geometry.RealRectangle2D[] queryMeasures( )
78 // TODO
79 return null;
82 public double[] queryLogicalAdvancements( )
84 // TODO
85 return null;
88 public void applyLogicalAdvancements( double[] aAdvancements ) throws com.sun.star.lang.IllegalArgumentException
90 if( aAdvancements.length != text.Length )
91 throw new com.sun.star.lang.IllegalArgumentException();
93 advancements = aAdvancements;
96 public com.sun.star.geometry.RealRectangle2D queryTextBounds( )
98 // TODO
99 return null;
102 public double justify( double nSize ) throws com.sun.star.lang.IllegalArgumentException
104 // TODO
105 return 0;
108 public double combinedJustify( XTextLayout[] aNextLayouts, double nSize ) throws com.sun.star.lang.IllegalArgumentException
110 // TODO
111 return 0;
114 public TextHit getTextHit( /*IN*/com.sun.star.geometry.RealPoint2D aHitPoint )
116 // TODO
117 return null;
120 public Caret getCaret( int nInsertionIndex, boolean bExcludeLigatures ) throws com.sun.star.lang.IndexOutOfBoundsException
122 // TODO
123 return null;
126 public int getNextInsertionIndex( int nStartIndex, int nCaretAdvancement, boolean bExcludeLigatures ) throws com.sun.star.lang.IndexOutOfBoundsException
128 // TODO
129 return 0;
132 public XPolyPolygon2D queryVisualHighlighting( int nStartIndex, int nEndIndex ) throws com.sun.star.lang.IndexOutOfBoundsException
134 // TODO
135 return null;
138 public XPolyPolygon2D queryLogicalHighlighting( int nStartIndex, int nEndIndex ) throws com.sun.star.lang.IndexOutOfBoundsException
140 // TODO
141 return null;
144 public double getBaselineOffset( )
146 // TODO
147 return 0.0;
150 public byte getMainTextDirection( )
152 return direction;
155 public XCanvasFont getFont( )
157 return font;
160 public StringContext getText( )
162 return text;
165 public boolean draw( java.awt.Graphics2D graphics )
167 // TODO: use proper advancement. Text direction need not be horizontal!
168 // TODO: given text string need not have a one-to-one relationship between code point and glyph (offset)!
169 graphics.drawString( text.Text.substring(text.StartPosition, text.StartPosition + 1), (float)0.0, (float)0.0 );
170 for( int i=1; i<advancements.length && i<text.Length; ++i )
172 CanvasUtils.printLog( "XCanvas: drawOffsettedText rendering a \"" +
173 text.Text.substring(text.StartPosition + i,
174 text.StartPosition + i + 1) +
175 "\" (position " + (text.StartPosition + i) +
176 " of " + text.Text + ", offset " + advancements[i] + ")" );
178 graphics.drawString( text.Text.substring(text.StartPosition + i, text.StartPosition + i + 1), (float)advancements[i-1], (float)0.0 );
181 return true;
184 //----------------------------------------------------------------------------------
187 // XServiceInfo impl
188 // =================
191 private static final String s_implName = "CanvasFont.java.impl";
192 private static final String s_serviceName = "com.sun.star.rendering.XCanvasFont";
194 public String getImplementationName()
196 return s_implName;
199 public String [] getSupportedServiceNames()
201 return new String [] { s_serviceName };
204 public boolean supportsService( String serviceName )
206 return serviceName.equals( s_serviceName );