1 /* 2 * Copyright (c) 2012, 2014, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. Oracle designates this 8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle in the LICENSE file that accompanied this code. 10 * 11 * This code is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 26 package com.sun.javafx.scene.text; 27 28 import javafx.scene.shape.PathElement; 29 import com.sun.javafx.geom.BaseBounds; 30 import com.sun.javafx.geom.Shape; 31 32 public interface TextLayout { 33 34 /* Internal flags Flags */ 35 static final int FLAGS_LINES_VALID = 1 << 0; /* unused */ 36 static final int FLAGS_ANALYSIS_VALID = 1 << 1; 37 static final int FLAGS_HAS_TABS = 1 << 2; 38 static final int FLAGS_HAS_BIDI = 1 << 3; 39 static final int FLAGS_HAS_COMPLEX = 1 << 4; 40 static final int FLAGS_HAS_EMBEDDED = 1 << 5; 41 static final int FLAGS_HAS_CJK = 1 << 6; 42 static final int FLAGS_WRAPPED = 1 << 7; 43 static final int FLAGS_RTL_BASE = 1 << 8; 44 static final int FLAGS_CACHED_UNDERLINE = 1 << 9; 45 static final int FLAGS_CACHED_STRIKETHROUGH = 1 << 10; 46 static final int FLAGS_LAST = 1 << 11; 47 48 static final int ANALYSIS_MASK = FLAGS_LAST - 1; 49 50 /* Text Layout compact internal representation */ 51 static final int ALIGN_LEFT = 1 << 18; 52 static final int ALIGN_CENTER = 1 << 19; 53 static final int ALIGN_RIGHT = 1 << 20; 54 static final int ALIGN_JUSTIFY = 1 << 21; 55 56 static final int ALIGN_MASK = ALIGN_LEFT | ALIGN_CENTER | 57 ALIGN_RIGHT | ALIGN_JUSTIFY; 58 59 public static final int DIRECTION_LTR = 1 << 10; 60 public static final int DIRECTION_RTL = 1 << 11; 61 public static final int DIRECTION_DEFAULT_LTR = 1 << 12; 62 public static final int DIRECTION_DEFAULT_RTL = 1 << 13; 63 64 static final int DIRECTION_MASK = DIRECTION_LTR | DIRECTION_RTL | 65 DIRECTION_DEFAULT_LTR | 66 DIRECTION_DEFAULT_RTL; 67 68 public static final int BOUNDS_CENTER = 1 << 14; 69 public static final int BOUNDS_MASK = BOUNDS_CENTER; 70 71 public static final int TYPE_TEXT = 1 << 0; 72 public static final int TYPE_UNDERLINE = 1 << 1; 73 public static final int TYPE_STRIKETHROUGH = 1 << 2; 74 public static final int TYPE_BASELINE = 1 << 3; 75 public static final int TYPE_TOP = 1 << 4; 76 public static final int TYPE_BEARINGS = 1 << 5; 77 78 /** 79 * Sets the content for the TextLayout. Supports multiple spans (rich text). 80 * 81 * @return returns true is the call modifies the layout internal state. 82 */ 83 public boolean setContent(TextSpan[] spans); 84 85 /** 86 * Sets the content for the TextLayout. Shorthand for single span text 87 * (no rich text). 88 * 89 * @return returns true is the call modifies the layout internal state. 90 */ 91 public boolean setContent(String string, Object font); 92 93 /** 94 * Sets the alignment for the TextLayout. 95 * 96 * @return returns true is the call modifies the layout internal state. 97 */ 98 public boolean setAlignment(/*TextAlignment*/ int alignment); 99 100 /** 101 * Sets the wrap width for the TextLayout. 102 * 103 * @return returns true is the call modifies the layout internal state. 104 */ 105 public boolean setWrapWidth(float wrapWidth); 106 107 /** 108 * Sets the line spacing for the TextLayout. 109 * 110 * @return returns true is the call modifies the layout internal state. 111 */ 112 public boolean setLineSpacing(float spacing); 113 114 /** 115 * Sets the direction (bidi algorithm's) for the TextLayout. 116 * 117 * @return returns true is the call modifies the layout internal state. 118 */ 119 public boolean setDirection(int direction); 120 121 /** 122 * Sets the bounds type for the TextLayout. 123 * 124 * @return returns true is the call modifies the layout internal state. 125 */ 126 public boolean setBoundsType(int type); 127 128 /** 129 * Returns the (logical) bounds of the layout 130 * minX is always zero 131 * minY is the ascent of the first line (negative) 132 * width the width of the widest line 133 * height the sum of all lines height 134 * 135 * Note that this width is different the wrapping width! 136 * 137 * @return the layout bounds 138 */ 139 public BaseBounds getBounds(); 140 141 public BaseBounds getBounds(TextSpan filter, BaseBounds bounds); 142 143 /** 144 * Returns the visual bounds of the layout using glyph bounding box 145 * 146 * @return the visual bounds 147 */ 148 public BaseBounds getVisualBounds(int type); 149 150 /** 151 * Returns the lines of text layout. 152 * 153 * @return the text lines 154 */ 155 public TextLine[] getLines(); 156 157 /** 158 * Returns the GlyphList of text layout. 159 * The runs are returned order visually (rendering order), starting 160 * from the first line. 161 * 162 * @return the runs 163 */ 164 public GlyphList[] getRuns(); 165 166 /** 167 * Returns the shape of the entire text layout relative to the baseline 168 * of the first line. 169 * 170 * @param type the type of the shapes to include 171 * @return the shape 172 */ 173 public Shape getShape(int type, TextSpan filter); 174 175 public HitInfo getHitInfo(float x, float y); 176 public PathElement[] getCaretShape(int offset, boolean isLeading, 177 float x, float y); 178 public PathElement[] getRange(int start, int end, int type, 179 float x, float y); 180 }