Changeset 1184 for trunk


Ignore:
Timestamp:
10/18/18 15:20:04 (6 years ago)
Author:
bln4
Message:

org.expeditee.gio.swing.SwingTextLayoutManager ->

Fixed a bug that was causing Frame titles on newly generated profiles (and other frames?) to have a their characters written one per line. The following is an explanation of the problem and solution that was implemented.

Due to the size of the font, combined with the length Frame title names tend to be, combined with the fact that they are only a single word, the SwingTextLayoutManager, which appears to contain code altered from before JFX snapshot, decides that these items are multiple lines long. This artificially inflates the size of the bounding box (needing an answer to determine it)!
The code as it was written in SwingTextLayoutManager.layoutString would first try laying out lines respecting the 'dontBreakWords' variable. When it cannot do this it chooses to ignore this variable and have a final attempt.
This final attempt however still respects the 'widthLimit' variable. The 'widthLimit' variable is a result of a (eventual) call to updateBounds(). This is therefore a chicken and egg situation.


My solution therefore is to: when giving up on attempting to respect the 'dontBreakWords' variable, also give up on the 'widthLimit' variable. This seems logical as, to break, it would require a scenario where we have a multi-word text item wherein the first word is too long to fit within width.
Further investigation is required to solve why the Y position of FrameTitle items are being positioned low.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/expeditee/gio/swing/SwingTextLayoutManager.java

    r1144 r1184  
    3131        public static SwingTextLayoutManager getInstance()
    3232        {
    33                 if (_instance == null) _instance = new SwingTextLayoutManager();
     33                if (_instance == null) {
     34                        _instance = new SwingTextLayoutManager();
     35                }
    3436               
    3537                return _instance;
     
    4648        private synchronized void register(TextLayout layout, java.awt.font.TextLayout swingLayout)
    4749        {
    48                 if (layout == null || swingLayout == null) return;
     50                if (layout == null || swingLayout == null) {
     51                        return;
     52                }
    4953               
    5054                _layoutMap.put(layout.getHandle(), swingLayout);
     
    5357        public synchronized java.awt.font.TextLayout getInternalLayout(TextLayout layout)
    5458        {
    55                 if (!isTextLayoutValid(layout)) return null;
     59                if (!isTextLayoutValid(layout)) {
     60                        return null;
     61                }
    5662               
    5763                return _layoutMap.get(layout.getHandle());
     
    6066        public synchronized boolean isTextLayoutValid(TextLayout layout)
    6167        {
    62                 if (layout == null) return false;
     68                if (layout == null) {
     69                        return false;
     70                }
    6371               
    6472                return _layoutMap.containsKey(layout.getHandle());
     
    6876        public float getAdvance(TextLayout layout)
    6977        {
    70                 if (!isTextLayoutValid(layout)) return Float.NaN;
     78                if (!isTextLayoutValid(layout)) {
     79                        return Float.NaN;
     80                }
    7181               
    7282                return getInternalLayout(layout).getAdvance();
     
    7686        public int getCharacterCount(TextLayout layout)
    7787        {
    78                 if (!isTextLayoutValid(layout)) return 0;
     88                if (!isTextLayoutValid(layout)) {
     89                        return 0;
     90                }
    7991               
    8092                return getInternalLayout(layout).getCharacterCount();
     
    8496        public TextHitInfo getNextLeftHit(TextLayout layout, int offset)
    8597        {
    86                 if (!isTextLayoutValid(layout)) return null;
     98                if (!isTextLayoutValid(layout)) {
     99                        return null;
     100                }
    87101               
    88102                return SwingConversions.fromSwingTextHitInfo(getInternalLayout(layout).getNextLeftHit(offset));
     
    92106        public TextHitInfo getNextLeftHit(TextLayout layout, TextHitInfo hit)
    93107        {
    94                 if (!isTextLayoutValid(layout)) return null;
     108                if (!isTextLayoutValid(layout)) {
     109                        return null;
     110                }
    95111               
    96112                return SwingConversions.fromSwingTextHitInfo(getInternalLayout(layout).getNextLeftHit(SwingConversions.toSwingTextHitInfo(hit)));
     
    100116        public TextHitInfo getNextRightHit(TextLayout layout, int offset)
    101117        {
    102                 if (!isTextLayoutValid(layout)) return null;
     118                if (!isTextLayoutValid(layout)) {
     119                        return null;
     120                }
    103121               
    104122                return SwingConversions.fromSwingTextHitInfo(getInternalLayout(layout).getNextRightHit(offset));
     
    108126        public TextHitInfo getNextRightHit(TextLayout layout, TextHitInfo hit)
    109127        {
    110                 if (!isTextLayoutValid(layout)) return null;
     128                if (!isTextLayoutValid(layout)) {
     129                        return null;
     130                }
    111131               
    112132                return SwingConversions.fromSwingTextHitInfo(getInternalLayout(layout).getNextRightHit(SwingConversions.toSwingTextHitInfo(hit)));
     
    116136        public float[] getCaretInfo(TextLayout layout, TextHitInfo hit)
    117137        {
    118                 if (!isTextLayoutValid(layout)) return null;
     138                if (!isTextLayoutValid(layout)) {
     139                        return null;
     140                }
    119141               
    120142                return getInternalLayout(layout).getCaretInfo(SwingConversions.toSwingTextHitInfo(hit));
     
    124146        public TextHitInfo hitTestChar(TextLayout layout, float x, float y)
    125147        {
    126                 if (!isTextLayoutValid(layout)) return null;
     148                if (!isTextLayoutValid(layout)) {
     149                        return null;
     150                }
    127151               
    128152                return SwingConversions.fromSwingTextHitInfo(getInternalLayout(layout).hitTestChar(x, y));
     
    132156        public AxisAlignedBoxBounds getPixelBounds(TextLayout layout, float x, float y)
    133157        {
    134                 if (!isTextLayoutValid(layout)) return null;
     158                if (!isTextLayoutValid(layout)) {
     159                        return null;
     160                }
    135161               
    136162                return SwingConversions.fromSwingRectangle(getInternalLayout(layout).getPixelBounds(null, x, y));
     
    140166        public AxisAlignedBoxBounds getLogicalHighlightShape(TextLayout layout, int firstEndpoint, int secondEndpoint)
    141167        {
    142                 if (!isTextLayoutValid(layout)) return null;
     168                if (!isTextLayoutValid(layout)) {
     169                        return null;
     170                }
    143171               
    144172                Rectangle rect = getInternalLayout(layout).getLogicalHighlightShape(firstEndpoint, secondEndpoint).getBounds();
     
    150178        public float getAscent(TextLayout layout)
    151179        {
    152                 if (!isTextLayoutValid(layout)) return Float.NaN;
     180                if (!isTextLayoutValid(layout)) {
     181                        return Float.NaN;
     182                }
    153183               
    154184                return getInternalLayout(layout).getAscent();
     
    158188        public float getDescent(TextLayout layout)
    159189        {
    160                 if (!isTextLayoutValid(layout)) return Float.NaN;
     190                if (!isTextLayoutValid(layout)) {
     191                        return Float.NaN;
     192                }
    161193               
    162194                return getInternalLayout(layout).getDescent();
     
    166198        public float getLeading(TextLayout layout)
    167199        {
    168                 if (!isTextLayoutValid(layout)) return Float.NaN;
     200                if (!isTextLayoutValid(layout)) {
     201                        return Float.NaN;
     202                }
    169203               
    170204                return getInternalLayout(layout).getLeading();
     
    174208        public synchronized void releaseLayout(TextLayout layout)
    175209        {
    176                 if (!isTextLayoutValid(layout)) return;
     210                if (!isTextLayoutValid(layout)) {
     211                        return;
     212                }
    177213               
    178214                _layoutMap.remove(layout.getHandle());
     
    182218        public List<TextLayout> layoutString(String string, Font font, Point start, Line[] lineBreakers, int widthLimit, int lineSpacing, boolean dontBreakWords, boolean fullJustify)
    183219        {
    184                 if (string == null || font == null || start == null) return null;
     220                if (string == null || font == null || start == null) {
     221                        return null;
     222                }
    185223               
    186224                // Make sure we have a swing font to use
    187225                java.awt.Font swingFont;
    188226                SwingFontManager fontManager = SwingMiscManager.getIfUsingSwingFontManager();
    189                 if (fontManager == null) return null;
     227                if (fontManager == null) {
     228                        return null;
     229                }
    190230                swingFont = fontManager.getInternalFont(font);
    191                 if (swingFont == null) return null;
     231                if (swingFont == null) {
     232                        return null;
     233                }
    192234               
    193235                // Temporary list to accumulate the TextLayouts in to
     
    209251                       
    210252                        int width = widthLimit;
    211                         if (lineBreakers != null) width = Math.min(width, (int) getLineWidth(start, lineBreakers));
     253                        if (lineBreakers != null) {
     254                                width = Math.min(width, (int) getLineWidth(start, lineBreakers));
     255                        }
    212256                       
    213257                        int end = string.length();
     
    223267                        // If it's impossible to layout any more text without breaking a word, just do it
    224268                        if (layout == null && width == widthLimit) {
    225                                 layout = lineBreaker.nextLayout(width, end, false);
     269                                layout = lineBreaker.nextLayout(Integer.MAX_VALUE, end, false);
    226270                                // If still impossible, give up
    227                                 if (layout == null) break;
     271                               
     272                                if (layout == null) {
     273                                        break;
     274                                }
    228275                        }
    229276
     
    266313                SwingFontManager f = SwingMiscManager.getIfUsingSwingFontManager();
    267314               
    268                 if (g == null || f == null) return -1;
     315                if (g == null || f == null) {
     316                        return -1;
     317                }
    269318               
    270319                if (font != null) {
Note: See TracChangeset for help on using the changeset viewer.