1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: TextLayout.java,v $
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 ************************************************************************/
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
,
54 direction
= nDirection
;
55 associatedCanvas
= _canvas
;
60 // XTextLayout implementation
61 // ==========================
64 public XPolyPolygon2D
[] queryTextShapes( )
70 public com
.sun
.star
.geometry
.RealRectangle2D
[] queryInkMeasures( )
76 public com
.sun
.star
.geometry
.RealRectangle2D
[] queryMeasures( )
82 public double[] queryLogicalAdvancements( )
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( )
102 public double justify( double nSize
) throws com
.sun
.star
.lang
.IllegalArgumentException
108 public double combinedJustify( XTextLayout
[] aNextLayouts
, double nSize
) throws com
.sun
.star
.lang
.IllegalArgumentException
114 public TextHit
getTextHit( /*IN*/com
.sun
.star
.geometry
.RealPoint2D aHitPoint
)
120 public Caret
getCaret( int nInsertionIndex
, boolean bExcludeLigatures
) throws com
.sun
.star
.lang
.IndexOutOfBoundsException
126 public int getNextInsertionIndex( int nStartIndex
, int nCaretAdvancement
, boolean bExcludeLigatures
) throws com
.sun
.star
.lang
.IndexOutOfBoundsException
132 public XPolyPolygon2D
queryVisualHighlighting( int nStartIndex
, int nEndIndex
) throws com
.sun
.star
.lang
.IndexOutOfBoundsException
138 public XPolyPolygon2D
queryLogicalHighlighting( int nStartIndex
, int nEndIndex
) throws com
.sun
.star
.lang
.IndexOutOfBoundsException
144 public double getBaselineOffset( )
150 public byte getMainTextDirection( )
155 public XCanvasFont
getFont( )
160 public StringContext
getText( )
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 );
184 //----------------------------------------------------------------------------------
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()
199 public String
[] getSupportedServiceNames()
201 return new String
[] { s_serviceName
};
204 public boolean supportsService( String serviceName
)
206 return serviceName
.equals( s_serviceName
);