]> gitweb.fperrin.net Git - Dictionary.git/blob - jars/icu4j-4_2_1-src/src/com/ibm/richtext/textformat/LayoutInfo.java
icu4jsrc
[Dictionary.git] / jars / icu4j-4_2_1-src / src / com / ibm / richtext / textformat / LayoutInfo.java
1 /*\r
2  * (C) Copyright IBM Corp. 1998-2004.  All Rights Reserved.\r
3  *\r
4  * The program is provided "as is" without any warranty express or\r
5  * implied, including the warranty of non-infringement and the implied\r
6  * warranties of merchantibility and fitness for a particular purpose.\r
7  * IBM will not be liable for any damages suffered by you as a result\r
8  * of using the Program. In no event will IBM be liable for any\r
9  * special, indirect or consequential damages or lost profits even if\r
10  * IBM has been advised of the possibility of their occurrence. IBM\r
11  * will not be liable for any third party claims against you.\r
12  */\r
13 // Requires Java2\r
14 /** LayoutInfo\r
15 \r
16     A line of text, possibly containing tab-segments.\r
17 */\r
18 \r
19 package com.ibm.richtext.textformat;\r
20 \r
21 import java.awt.Color;\r
22 import java.awt.Rectangle;\r
23 \r
24 ///*JDK12IMPORTS\r
25 import java.awt.Graphics2D;\r
26 //JDK12IMPORTS*/\r
27 \r
28 /*JDK11IMPORTS\r
29 import com.ibm.richtext.textlayout.Graphics2D;\r
30 JDK11IMPORTS*/\r
31 \r
32 import com.ibm.richtext.styledtext.MConstText;\r
33 \r
34 abstract class LayoutInfo\r
35 {\r
36     static final String COPYRIGHT =\r
37                 "(C) Copyright IBM Corp. 1998-1999 - All Rights Reserved";\r
38     private int fCharStart;       // offset in text to start of line (was fStart)\r
39                                   // neg. values indicate distance from end of text\r
40     private int fGraphicStart;    // min pixel offset in fill direction\r
41                                   // negative values indicate distance from bottom of text view\r
42 \r
43     /*\r
44         These methods are for storing Layouts in a gap-storage,\r
45         relative to either the start of end of text.  See AsyncFormatter.\r
46 \r
47         If you just want absolute (that is, start-relative) char and\r
48         graphic starts, don't make them end-relative.\r
49     */\r
50 \r
51     public final int getCharStart(int lengthBasis) {\r
52 \r
53         if (fCharStart >= 0) {\r
54             return fCharStart;\r
55         }\r
56         else {\r
57             return lengthBasis + fCharStart;\r
58         }\r
59     }\r
60 \r
61     public final int getGraphicStart(int graphicBasis) {\r
62 \r
63         if (fGraphicStart >= 0) {\r
64             return fGraphicStart;\r
65         }\r
66         else {\r
67             return graphicBasis + fGraphicStart;\r
68         }\r
69     }\r
70 \r
71     public final void setCharStart(int beginningRelativeStart) {\r
72 \r
73         if (beginningRelativeStart < 0) {\r
74             throw new IllegalArgumentException("charStart must be nonnegavitve");\r
75         }\r
76         fCharStart = beginningRelativeStart;\r
77     }\r
78 \r
79     public final void setGraphicStart(int beginningRelativeStart) {\r
80 \r
81         if (beginningRelativeStart < 0) {\r
82             throw new IllegalArgumentException("charStart must be nonnegavitve");\r
83         }\r
84         fGraphicStart = beginningRelativeStart;\r
85     }\r
86 \r
87     public final void makeRelativeToBeginning(int lengthBasis,\r
88                                               int graphicBasis) {\r
89 \r
90         if (lengthBasis < 0 || graphicBasis < 0) {\r
91             throw new IllegalArgumentException("Bases must be positive.");\r
92         }\r
93         if (fCharStart >= 0 || fGraphicStart >= 0) {\r
94             throw new Error("Already start-relative.");\r
95         }\r
96 \r
97         fCharStart += lengthBasis;\r
98         fGraphicStart += graphicBasis;\r
99     }\r
100 \r
101     public final void makeRelativeToEnd(int lengthBasis,\r
102                                         int graphicBasis) {\r
103 \r
104         if (lengthBasis < 0 || graphicBasis < 0) {\r
105             throw new IllegalArgumentException("Bases must be positive.");\r
106         }\r
107         if (fCharStart < 0 || fGraphicStart < 0) {\r
108             throw new Error("Already end-relative.");\r
109         }\r
110 \r
111         fCharStart -= lengthBasis;\r
112         fGraphicStart -= graphicBasis;\r
113     }\r
114 \r
115 \r
116     public abstract int getCharLength();\r
117     public abstract int getAscent();\r
118     public abstract int getDescent();\r
119     public abstract int getLeading();\r
120 \r
121     public abstract int getVisibleAdvance();\r
122     public abstract int getTotalAdvance();\r
123     public abstract int getLeadingMargin();\r
124 \r
125     public abstract boolean isLeftToRight();\r
126 \r
127     public int getHeight() {\r
128 \r
129         return getAscent()+getDescent()+getLeading();\r
130     }\r
131 \r
132     /**\r
133     * Draws text with highlighting.\r
134     */\r
135     public void renderWithHighlight(int lengthBasis,\r
136                                     Graphics2D g,\r
137                                     int lineBound,\r
138                                     int x,\r
139                                     int y,\r
140                                     TextOffset selStart,\r
141                                     TextOffset selStop,\r
142                                     Color highlightColor)\r
143     {\r
144     }\r
145 \r
146     /** Use layout information to render the line at x, y.*/\r
147 \r
148     public void render(int lengthBasis,\r
149                        Graphics2D g,\r
150                        int lineBound,\r
151                        int x,\r
152                        int y)\r
153     {\r
154     }\r
155 \r
156     public void renderCaret(MConstText text,\r
157                             int lengthBasis,\r
158                             Graphics2D g,\r
159                             int lineBound,\r
160                             int x,\r
161                             int y,\r
162                             int charOffset,\r
163                             Color strongCaretColor,\r
164                             Color weakCaretColor)\r
165     {\r
166     }\r
167 \r
168     /**\r
169      * Given a point within this line, return the character offset corresponding to that point.\r
170      *\r
171      * @param result.  This may be null, in which case a new TextOffset will be allocated.\r
172      *        This object is modified in place, and also returned as the function result.\r
173      * @param text Text to inspect.\r
174      * @param lineX Position on this line relative to top left corner of this line.\r
175      * @param lineY Position on this line relative to top left corner of this line.\r
176      */\r
177     public abstract TextOffset pixelToOffset(int lengthBasis,\r
178                                              TextOffset result,\r
179                                              int lineBound,\r
180                                              int x,\r
181                                              int y);\r
182 \r
183     public abstract int strongCaretBaselinePosition(int lengthBasis,\r
184                                                     int lineBound,\r
185                                                     int charOffset);\r
186 \r
187     public abstract Rectangle caretBounds(MConstText text,\r
188                                           int lengthBasis,\r
189                                           int lineBound,\r
190                                           int charOffset,\r
191                                           int x,\r
192                                           int y);\r
193     \r
194     public abstract int getNextOffset(int lengthBasis,\r
195                                       int charOffset,\r
196                                       short dir);\r
197 }\r