HighlightsViewUtils.java 文件源码

java
阅读 25 收藏 0 点赞 0 评论 0

项目:incubator-netbeans 作者:
static Shape indexToView(TextLayout textLayout, Rectangle2D textLayoutBounds,
            int index, Position.Bias bias, int maxIndex, Shape alloc)
   {
       if (textLayout == null) {
           return alloc; // Leave given bounds
       }
       assert (maxIndex <= textLayout.getCharacterCount()) : "textLayout.getCharacterCount()=" + // NOI18N
               textLayout.getCharacterCount() + " < maxIndex=" + maxIndex; // NOI18N
       // If offset is >getEndOffset() use view-end-offset - otherwise it would throw exception from textLayout.getCaretInfo()
int charIndex = Math.min(index, maxIndex);
       // When e.g. creating fold-preview the offset can be < startOffset
       charIndex = Math.max(charIndex, 0);
       TextHitInfo startHit;
       TextHitInfo endHit;
       if (bias == Position.Bias.Forward) {
           startHit = TextHitInfo.leading(charIndex);
       } else { // backward bias
           startHit = TextHitInfo.trailing(charIndex - 1);
       }
       endHit = (charIndex < maxIndex) ? TextHitInfo.trailing(charIndex) : startHit;
       if (textLayoutBounds == null) {
           textLayoutBounds = ViewUtils.shapeAsRect(alloc);
       }
       return TextLayoutUtils.getRealAlloc(textLayout, textLayoutBounds, startHit, endHit);
   }
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号