[haiku-commits] haiku: hrev46024 - src/apps/haiku-depot/textview

  • From: superstippi@xxxxxx
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Fri, 6 Sep 2013 10:04:23 +0200 (CEST)

hrev46024 adds 3 changesets to branch 'master'
old head: fcc745e0e756f2d7700b138d435f0fabd2262d66
new head: 00861147be6003276aa646bbca3ef3cb2cbf3ed3
overview: http://cgit.haiku-os.org/haiku/log/?qt=range&q=0086114+%5Efcc745e

----------------------------------------------------------------------------

822872d: Paragraph: Added Clear() method to remove all TextChunks.

8d0c791: HaikuDepot: Switched TextView to use new ParagraphLayout
  
   * The ParagraphStyle can be set as well.

0086114: HaikuDepot: Removed first iteration of text layout classes.

                                      [ Stephan Aßmus <superstippi@xxxxxx> ]

----------------------------------------------------------------------------

11 files changed, 41 insertions(+), 984 deletions(-)
src/apps/haiku-depot/Jamfile                 |   4 +-
src/apps/haiku-depot/textview/GlyphInfo.h    | 100 ----
src/apps/haiku-depot/textview/LineInfo.h     |  80 ----
src/apps/haiku-depot/textview/Paragraph.cpp  |   7 +
src/apps/haiku-depot/textview/Paragraph.h    |   1 +
src/apps/haiku-depot/textview/TextLayout.cpp | 562 -----------------------
src/apps/haiku-depot/textview/TextLayout.h   |  85 ----
src/apps/haiku-depot/textview/TextStyle.cpp  |  97 ----
src/apps/haiku-depot/textview/TextStyle.h    |  50 --
src/apps/haiku-depot/textview/TextView.cpp   |  32 +-
src/apps/haiku-depot/textview/TextView.h     |   7 +-

############################################################################

Commit:      822872d6c34ed72f90a5d60fb180b6d268085658
URL:         http://cgit.haiku-os.org/haiku/commit/?id=822872d
Author:      Stephan Aßmus <superstippi@xxxxxx>
Date:        Fri Sep  6 08:02:06 2013 UTC

Paragraph: Added Clear() method to remove all TextChunks.

----------------------------------------------------------------------------

diff --git a/src/apps/haiku-depot/textview/Paragraph.cpp 
b/src/apps/haiku-depot/textview/Paragraph.cpp
index 43157eb3..26ad3e9 100644
--- a/src/apps/haiku-depot/textview/Paragraph.cpp
+++ b/src/apps/haiku-depot/textview/Paragraph.cpp
@@ -125,6 +125,13 @@ Paragraph::Insert(int32 offset, const TextSpan& newSpan)
 }
 
 
+void
+Paragraph::Clear()
+{
+       fTextSpans.Clear();
+}
+
+
 int32
 Paragraph::Length() const
 {
diff --git a/src/apps/haiku-depot/textview/Paragraph.h 
b/src/apps/haiku-depot/textview/Paragraph.h
index 512189e..4ad83f4 100644
--- a/src/apps/haiku-depot/textview/Paragraph.h
+++ b/src/apps/haiku-depot/textview/Paragraph.h
@@ -32,6 +32,7 @@ public:
 
                        bool                            Append(const TextSpan& 
span);
                        bool                            Insert(int32 offset, 
const TextSpan& span);
+                       void                            Clear();
 
                        int32                           Length() const;
 

############################################################################

Commit:      8d0c791d5f3ad6837ea6d0c695e46ed6b6e298c9
URL:         http://cgit.haiku-os.org/haiku/commit/?id=8d0c791
Author:      Stephan Aßmus <superstippi@xxxxxx>
Date:        Fri Sep  6 08:02:33 2013 UTC

HaikuDepot: Switched TextView to use new ParagraphLayout

 * The ParagraphStyle can be set as well.

----------------------------------------------------------------------------

diff --git a/src/apps/haiku-depot/textview/TextView.cpp 
b/src/apps/haiku-depot/textview/TextView.cpp
index cd41dec..836b401 100644
--- a/src/apps/haiku-depot/textview/TextView.cpp
+++ b/src/apps/haiku-depot/textview/TextView.cpp
@@ -10,11 +10,16 @@ TextView::TextView(const char* name)
        :
        BView(name, B_WILL_DRAW | B_FULL_UPDATE_ON_RESIZE | B_FRAME_EVENTS)
 {
-       fTextLayout.SetWidth(Bounds().Width());
-       fTextLayout.SetLineSpacing(ceilf(fTextLayout.Font().Size() * 0.2));
-
        SetViewColor(B_TRANSPARENT_COLOR);
        SetLowColor(ui_color(B_PANEL_BACKGROUND_COLOR));
+
+       BFont font;
+       GetFont(&font);
+
+       ParagraphStyle style;
+       style.SetLineSpacing(ceilf(font.Size() * 0.2));
+       
+       SetParagraphStyle(style);
 }
 
 
@@ -81,7 +86,7 @@ void
 TextView::GetHeightForWidth(float width, float* min, float* max,
        float* preferred)
 {
-       TextLayout layout(fTextLayout);
+       ParagraphLayout layout(fTextLayout);
        layout.SetWidth(width);
 
        float height = layout.Height() + 1;
@@ -98,6 +103,23 @@ TextView::GetHeightForWidth(float width, float* min, float* 
max,
 void
 TextView::SetText(const BString& text)
 {
-       fTextLayout.SetText(text);
+       fText.Clear();
+
+       CharacterStyle regularStyle;
+       fText.Append(TextSpan(text, regularStyle));
+
+       fTextLayout.SetParagraph(fText);
+       
+       InvalidateLayout();
+}
+
+
+void
+TextView::SetParagraphStyle(const ParagraphStyle& style)
+{
+       fText.SetStyle(style);
+       fTextLayout.SetParagraph(fText);
+
+       InvalidateLayout();
 }
 
diff --git a/src/apps/haiku-depot/textview/TextView.h 
b/src/apps/haiku-depot/textview/TextView.h
index 6f31f2c..109a011 100644
--- a/src/apps/haiku-depot/textview/TextView.h
+++ b/src/apps/haiku-depot/textview/TextView.h
@@ -8,7 +8,8 @@
 #include <String.h>
 #include <View.h>
 
-#include "TextLayout.h"
+#include "Paragraph.h"
+#include "ParagraphLayout.h"
 
 
 class TextView : public BView {
@@ -30,9 +31,11 @@ public:
                                                                        float* 
max, float* preferred);
 
                        void                            SetText(const BString& 
text);
+                       void                            SetParagraphStyle(const 
ParagraphStyle& style);
 
 private:
-                       TextLayout                      fTextLayout;
+                       Paragraph                       fText;
+                       ParagraphLayout         fTextLayout;
 };
 
 #endif // TEXT_VIEW_H

############################################################################

Revision:    hrev46024
Commit:      00861147be6003276aa646bbca3ef3cb2cbf3ed3
URL:         http://cgit.haiku-os.org/haiku/commit/?id=0086114
Author:      Stephan Aßmus <superstippi@xxxxxx>
Date:        Fri Sep  6 08:03:13 2013 UTC

HaikuDepot: Removed first iteration of text layout classes.

----------------------------------------------------------------------------

diff --git a/src/apps/haiku-depot/Jamfile b/src/apps/haiku-depot/Jamfile
index 961337d..3681439 100644
--- a/src/apps/haiku-depot/Jamfile
+++ b/src/apps/haiku-depot/Jamfile
@@ -24,9 +24,7 @@ local textDocumentSources =
        TextDocument.cpp
        TextDocumentLayout.cpp
        TextDocumentView.cpp
-       TextLayout.cpp
        TextSpan.cpp
-       TextStyle.cpp
        TextView.cpp
 ;
 
@@ -44,7 +42,7 @@ Application HaikuDepot :
        PackageManager.cpp
        support.cpp
 
-       # textview stuff
+       # text view stuff
        $(textDocumentSources)
        
        : be translation libcolumnlistview.a libshared.a $(TARGET_LIBSUPC++)
diff --git a/src/apps/haiku-depot/textview/GlyphInfo.h 
b/src/apps/haiku-depot/textview/GlyphInfo.h
deleted file mode 100644
index 74d70b2..0000000
--- a/src/apps/haiku-depot/textview/GlyphInfo.h
+++ /dev/null
@@ -1,100 +0,0 @@
-/*
- * Copyright 2013, Stephan Aßmus <superstippi@xxxxxx>.
- * All rights reserved. Distributed under the terms of the MIT License.
- */
-#ifndef GLYPH_INFO_H
-#define GLYPH_INFO_H
-
-#include "TextStyle.h"
-
-
-class GlyphInfo {
-public:
-       GlyphInfo()
-               :
-               charCode(0),
-               x(0.0f),
-               y(0.0f),
-               advanceX(0.0f),
-               maxAscent(0.0f),
-               maxDescent(0.0f),
-               lineIndex(0),
-               style()
-       {
-       }
-
-       GlyphInfo(uint32 charCode, float x, float y, float advanceX,
-                       float maxAscent, float maxDescent, int lineIndex,
-                       const TextStyleRef& style)
-               :
-               charCode(charCode),
-               x(x),
-               y(y),
-               advanceX(advanceX),
-               maxAscent(maxAscent),
-               maxDescent(maxDescent),
-               lineIndex(lineIndex),
-               style(style)
-       {
-       }
-       
-       GlyphInfo(const GlyphInfo& other)
-               :
-               charCode(other.charCode),
-               x(other.x),
-               y(other.y),
-               advanceX(other.advanceX),
-               maxAscent(other.maxAscent),
-               maxDescent(other.maxDescent),
-               lineIndex(other.lineIndex),
-               style(other.style)
-       {
-       }
-
-       GlyphInfo& operator=(const GlyphInfo& other)
-       {
-               charCode = other.charCode;
-               x = other.x;
-               y = other.y;
-               advanceX = other.advanceX;
-               maxAscent = other.maxAscent;
-               maxDescent = other.maxDescent;
-               lineIndex = other.lineIndex;
-               style = other.style;
-               return *this;
-       }
-
-       bool operator==(const GlyphInfo& other) const
-       {
-               return charCode == other.charCode
-                       && x == other.x
-                       && y == other.y
-                       && advanceX == other.advanceX
-                       && maxAscent == other.maxAscent
-                       && maxDescent == other.maxDescent
-                       && lineIndex == other.lineIndex
-                       && style == other.style;
-       }
-
-       bool operator!=(const GlyphInfo& other) const
-       {
-               return !(*this == other);
-       }
-
-public:
-       uint32                                  charCode;
-
-       float                                   x;
-       float                                   y;
-       float                                   advanceX;
-
-       float                                   maxAscent;
-       float                                   maxDescent;
-
-       int                                             lineIndex;
-
-       TextStyleRef                    style;
-};
-
-
-#endif // GLYPH_INFO_H
diff --git a/src/apps/haiku-depot/textview/LineInfo.h 
b/src/apps/haiku-depot/textview/LineInfo.h
deleted file mode 100644
index 4d41c82..0000000
--- a/src/apps/haiku-depot/textview/LineInfo.h
+++ /dev/null
@@ -1,80 +0,0 @@
-/*
- * Copyright 2013, Stephan Aßmus <superstippi@xxxxxx>.
- * All rights reserved. Distributed under the terms of the MIT License.
- */
-#ifndef LINE_INFO_H
-#define LINE_INFO_H
-
-#include "List.h"
-
-
-class LineInfo {
-public:
-       LineInfo()
-               :
-               textOffset(0),
-               y(0.0f),
-               height(0.0f),
-               maxAscent(0.0f),
-               maxDescent(0.0f)
-       {
-       }
-       
-       LineInfo(int textOffset, float y, float height, float maxAscent,
-                       float maxDescent)
-               :
-               textOffset(textOffset),
-               y(y),
-               height(height),
-               maxAscent(maxAscent),
-               maxDescent(maxDescent)
-       {
-       }
-       
-       LineInfo(const LineInfo& other)
-               :
-               textOffset(other.textOffset),
-               y(other.y),
-               height(other.height),
-               maxAscent(other.maxAscent),
-               maxDescent(other.maxDescent)
-       {
-       }
-
-       LineInfo& operator=(const LineInfo& other)
-       {
-               textOffset = other.textOffset;
-               y = other.y;
-               height = other.height;
-               maxAscent = other.maxAscent;
-               maxDescent = other.maxDescent;
-               return *this;
-       }
-
-       bool operator==(const LineInfo& other) const
-       {
-               return textOffset == other.textOffset
-                       && y == other.y
-                       && height == other.height
-                       && maxAscent == other.maxAscent
-                       && maxDescent == other.maxDescent;
-       }
-
-       bool operator!=(const LineInfo& other) const
-       {
-               return !(*this == other);
-       }
-
-public:
-       int             textOffset;
-       float   y;
-       float   height;
-       float   maxAscent;
-       float   maxDescent;
-};
-
-
-typedef List<LineInfo, false> LineInfoList;
-
-
-#endif // LINE_INFO_H
diff --git a/src/apps/haiku-depot/textview/TextLayout.cpp 
b/src/apps/haiku-depot/textview/TextLayout.cpp
deleted file mode 100644
index 20eba50..0000000
--- a/src/apps/haiku-depot/textview/TextLayout.cpp
+++ /dev/null
@@ -1,562 +0,0 @@
-/*
- * Copyright 2001-2013, Haiku, Inc. All rights reserved.
- * Distributed under the terms of the MIT License.
- *
- * Authors:
- *             Stephan Aßmus, superstippi@xxxxxx
- *             Stefano Ceccherini, stefano.ceccherini@xxxxxxxxx
- *             Marc Flerackers, mflerackers@xxxxxxxxxx
- *             Hiroshi Lockheimer (BTextView is based on his STEEngine)
- *             Oliver Tappe, zooey@xxxxxxxxxxxxxxx
- */
-
-#include "TextLayout.h"
-
-#include <new>
-#include <stdio.h>
-
-#include <AutoDeleter.h>
-#include <utf8_functions.h>
-#include <View.h>
-
-#include "GlyphInfo.h"
-#include "List.h"
-#include "TextStyle.h"
-
-
-enum {
-       CHAR_CLASS_DEFAULT,
-       CHAR_CLASS_WHITESPACE,
-       CHAR_CLASS_GRAPHICAL,
-       CHAR_CLASS_QUOTE,
-       CHAR_CLASS_PUNCTUATION,
-       CHAR_CLASS_PARENS_OPEN,
-       CHAR_CLASS_PARENS_CLOSE,
-       CHAR_CLASS_END_OF_TEXT
-};
-
-
-inline uint32
-get_char_classification(uint32 charCode)
-{
-       // TODO: Should check against a list of characters containing also
-       // word breakers from other languages.
-
-       switch (charCode) {
-               case '\0':
-                       return CHAR_CLASS_END_OF_TEXT;
-
-               case ' ':
-               case '\t':
-               case '\n':
-                       return CHAR_CLASS_WHITESPACE;
-
-               case '=':
-               case '+':
-               case '@':
-               case '#':
-               case '$':
-               case '%':
-               case '^':
-               case '&':
-               case '*':
-               case '\\':
-               case '|':
-               case '<':
-               case '>':
-               case '/':
-               case '~':
-                       return CHAR_CLASS_GRAPHICAL;
-
-               case '\'':
-               case '"':
-                       return CHAR_CLASS_QUOTE;
-
-               case ',':
-               case '.':
-               case '?':
-               case '!':
-               case ';':
-               case ':':
-               case '-':
-                       return CHAR_CLASS_PUNCTUATION;
-
-               case '(':
-               case '[':
-               case '{':
-                       return CHAR_CLASS_PARENS_OPEN;
-
-               case ')':
-               case ']':
-               case '}':
-                       return CHAR_CLASS_PARENS_CLOSE;
-
-               default:
-                       return CHAR_CLASS_DEFAULT;
-       }
-}
-
-
-inline bool
-can_end_line(const GlyphInfo* buffer, int offset, int count)
-{
-       if (offset == count - 1)
-               return true;
-
-       if (offset < 0 || offset > count)
-               return false;
-
-       uint32 charCode = buffer[offset].charCode;
-       uint32 classification = get_char_classification(charCode);
-
-       // wrapping is always allowed at end of text and at newlines
-       if (classification == CHAR_CLASS_END_OF_TEXT || charCode == '\n')
-               return true;
-
-       uint32 nextCharCode = buffer[offset + 1].charCode;
-       uint32 nextClassification = get_char_classification(nextCharCode);
-
-       // never separate a punctuation char from its preceding word
-       if (classification == CHAR_CLASS_DEFAULT
-               && nextClassification == CHAR_CLASS_PUNCTUATION) {
-               return false;
-       }
-
-       if ((classification == CHAR_CLASS_WHITESPACE
-                       && nextClassification != CHAR_CLASS_WHITESPACE)
-               || (classification != CHAR_CLASS_WHITESPACE
-                       && nextClassification == CHAR_CLASS_WHITESPACE)) {
-               return true;
-       }
-
-       // allow wrapping after whitespace, unless more whitespace (except for
-       // newline) follows
-       if (classification == CHAR_CLASS_WHITESPACE
-               && (nextClassification != CHAR_CLASS_WHITESPACE
-                       || nextCharCode == '\n')) {
-               return true;
-       }
-
-       // allow wrapping after punctuation chars, unless more punctuation, 
closing
-       // parenthesis or quotes follow
-       if (classification == CHAR_CLASS_PUNCTUATION
-               && nextClassification != CHAR_CLASS_PUNCTUATION
-               && nextClassification != CHAR_CLASS_PARENS_CLOSE
-               && nextClassification != CHAR_CLASS_QUOTE) {
-               return true;
-       }
-
-       // allow wrapping after quotes, graphical chars and closing parenthesis 
only
-       // if whitespace follows (not perfect, but seems to do the right thing 
most
-       // of the time)
-       if ((classification == CHAR_CLASS_QUOTE
-                       || classification == CHAR_CLASS_GRAPHICAL
-                       || classification == CHAR_CLASS_PARENS_CLOSE)
-               && nextClassification == CHAR_CLASS_WHITESPACE) {
-               return true;
-       }
-
-       return false;
-}
-
-
-// #pragma mark - TextLayout
-
-
-TextLayout::TextLayout()
-       :
-       fText(),
-
-       fDefaultFont(),
-       fAscent(0.0f),
-       fDescent(0.0f),
-       fWidth(0.0f),
-       fGlyphSpacing(0.0f),
-       fFirstLineInset(0.0f),
-       fLineInset(0.0f),
-       fLineSpacing(0.0f),
-
-       fLayoutValid(false),
-       fGlyphInfoBuffer(NULL),
-       fGlyphInfoCount(0)
-{
-       // Init fAscent and fDescent
-       SetFont(BFont(be_plain_font));
-}
-
-
-TextLayout::TextLayout(const TextLayout& other)
-       :
-       fText(other.fText),
-
-       fDefaultFont(other.fDefaultFont),
-       fAscent(other.fAscent),
-       fDescent(other.fDescent),
-       fWidth(other.fWidth),
-       fGlyphSpacing(other.fGlyphSpacing),
-       fFirstLineInset(other.fFirstLineInset),
-       fLineInset(other.fLineInset),
-       fLineSpacing(other.fLineSpacing),
-
-       fLayoutValid(false),
-       fGlyphInfoBuffer(NULL),
-       fGlyphInfoCount(0)
-{
-}
-
-
-TextLayout::~TextLayout()
-{
-       delete[] fGlyphInfoBuffer;
-}
-
-
-void
-TextLayout::SetText(const BString& text)
-{
-       if (fText != text) {
-               fText = text;
-               fLayoutValid = false;
-       }
-}
-
-
-void
-TextLayout::SetFont(const BFont& font)
-{
-       if (fDefaultFont != font || fAscent == 0.0f) {
-               fDefaultFont = font;
-
-               font_height fontHeight;
-               font.GetHeight(&fontHeight);
-
-               fAscent = fontHeight.ascent;
-               fDescent = fontHeight.descent;
-
-               fLayoutValid = false;
-       }
-}
-
-
-void
-TextLayout::SetGlyphSpacing(float glyphSpacing)
-{
-       if (fGlyphSpacing != glyphSpacing) {
-               fGlyphSpacing = glyphSpacing;
-               fLayoutValid = false;
-       }
-}
-
-
-void
-TextLayout::SetFirstLineInset(float inset)
-{
-       if (fFirstLineInset != inset) {
-               fFirstLineInset = inset;
-               fLayoutValid = false;
-       }
-}
-
-
-void
-TextLayout::SetLineInset(float inset)
-{
-       if (fLineInset != inset) {
-               fLineInset = inset;
-               fLayoutValid = false;
-       }
-}
-
-
-void
-TextLayout::SetLineSpacing(float spacing)
-{
-       if (fLineSpacing != spacing) {
-               fLineSpacing = spacing;
-               fLayoutValid = false;
-       }
-}
-
-
-void
-TextLayout::SetWidth(float width)
-{
-       if (fWidth != width) {
-               fWidth = width;
-               fLayoutValid = false;
-       }
-}
-
-
-float
-TextLayout::Height()
-{
-       _ValidateLayout();
-
-       float height = fDefaultFont.Size();
-
-       if (fLineInfos.CountItems() > 0) {
-               const LineInfo& lastLine = fLineInfos.LastItem();
-               height = lastLine.y + lastLine.height;
-       }
-
-       return height;
-}
-
-
-void
-TextLayout::Draw(BView* view, const BPoint& offset)
-{
-       _ValidateLayout();
-       
-       // TODO: Support styles and all
-       view->SetFont(&fDefaultFont);
-       view->SetHighColor(0, 0, 0);
-       
-       int lineCount = fLineInfos.CountItems();
-       for (int i = 0; i < lineCount; i++) {
-               const LineInfo& line = fLineInfos.ItemAtFast(i);
-               
-               int startOffset = line.textOffset;
-               int endOffset;
-               if (i < lineCount - 1) {
-                       const LineInfo& nextLine = fLineInfos.ItemAtFast(i + 1);
-                       endOffset = nextLine.textOffset;
-               } else {
-                       endOffset = fGlyphInfoCount;
-               }
-               
-               BString string;
-               fText.CopyCharsInto(string, startOffset, endOffset - 
startOffset);
-               
-               float x = fGlyphInfoBuffer[startOffset].x;
-               float y = fGlyphInfoBuffer[startOffset].y;
-
-//printf("%p->%.1f,%.1f: '%s'\n", this, x, y, string.String());
-               view->DrawString(string, BPoint(x, y));
-       }
-}
-
-
-// #pragma mark - private
-
-
-void
-TextLayout::_ValidateLayout()
-{
-       if (!fLayoutValid)
-               _Layout();
-}
-
-
-void
-TextLayout::_Layout()
-{
-       fLineInfos.Clear();
-       delete[] fGlyphInfoBuffer;
-       fGlyphInfoBuffer = NULL;
-
-       fGlyphInfoCount = fText.CountChars();
-       if (fGlyphInfoCount == 0)
-               return;
-       
-       // Allocate arrays
-       float* escapementArray = new (std::nothrow) float[fGlyphInfoCount];
-       if (escapementArray == NULL)
-               return;
-       ArrayDeleter<float> escapementDeleter(escapementArray);
-
-       // Fetch glyph spacing information
-       fDefaultFont.GetEscapements(fText.String(), fGlyphInfoCount,
-               escapementArray);
-
-       // Convert to glyph buffer
-       fGlyphInfoBuffer = new (std::nothrow) GlyphInfo[fGlyphInfoCount];
-       
-       // Init glyph buffer and convert escapement scale
-       float size = fDefaultFont.Size();
-       const char* c = fText.String();
-       for (int i = 0; i < fGlyphInfoCount; i++) {
-               fGlyphInfoBuffer[i].charCode = UTF8ToCharCode(&c);
-               escapementArray[i] *= size;
-       }
-
-
-       float x = fFirstLineInset;
-       float y = 0.0f;
-       int lineIndex = 0;
-       int lineStart = 0;
-
-       for (int i = 0; i < fGlyphInfoCount; i++) {
-               uint32 charClassification = get_char_classification(
-                       fGlyphInfoBuffer[i].charCode);
-
-               float advanceX = 0.0f;
-               float advanceY = 0.0f;
-               _GetGlyphAdvance(i, advanceX, advanceY, escapementArray);
-
-               bool nextLine = false;
-               bool lineBreak = false;
-
-//             if (fGlyphInfoBuffer[i].charCode == '\t') {
-//                     // Figure out tab width, it's the width between the 
last two tab
-//                     // stops.
-//                     float tabWidth = 0.0f;
-//                     if (fTabCount > 0)
-//                             tabWidth = fTabBuffer[fTabCount - 1];
-//                     if (fTabCount > 1)
-//                             tabWidth -= fTabBuffer[fTabCount - 2];
-//
-//                     // Try to find a tab stop that is farther than the 
current x
-//                     // offset
-//                     double tabOffset = 0.0;
-//                     for (unsigned tabIndex = 0; tabIndex < fTabCount; 
tabIndex++) {
-//                             tabOffset = fTabBuffer[tabIndex];
-//                             if (tabOffset > x)
-//                                     break;
-//                     }
-//
-//                     // If no tab stop has been found, make the tab stop a 
multiple of
-//                     // the tab width
-//                     if (tabOffset <= x && tabWidth > 0.0)
-//                             tabOffset = ((int) (x / tabWidth) + 1) * 
tabWidth;
-//
-//                     if (tabOffset - x > 0.0)
-//                             advanceX = tabOffset - x;
-//             }
-
-               fGlyphInfoBuffer[i].advanceX = advanceX;
-
-               if (fGlyphInfoBuffer[i].charCode == '\n') {
-                       nextLine = true;
-                       lineBreak = true;
-                       fGlyphInfoBuffer[i].x = x;
-                       fGlyphInfoBuffer[i].y = y;
-               } else if (fWidth > 0.0f && x + advanceX > fWidth) {
-                       if (charClassification == CHAR_CLASS_WHITESPACE) {
-                               advanceX = 0.0f;
-                       } else if (i > lineStart) {
-                               nextLine = true;
-                               // The current glyph extends outside the width, 
we need to wrap
-                               // to the next line. See what previous offset 
can be the end
-                               // of the line.
-                               int lineEnd = i - 1;
-                               while (lineEnd > lineStart
-                                       && !can_end_line(fGlyphInfoBuffer, 
lineEnd,
-                                               fGlyphInfoCount)) {
-                                       lineEnd--;
-                               }
-
-                               if (lineEnd > lineStart) {
-                                       // Found a place to perform a line 
break.
-                                       i = lineEnd + 1;
-                                       // Adjust the glyph info to point at 
the changed buffer
-                                       // position
-                                       _GetGlyphAdvance(i, advanceX, advanceY, 
escapementArray);
-                               } else {
-                                       // Just break where we are.
-                               }
-                       }
-               }
-
-               if (nextLine) {
-                       // * Initialize the max ascent/descent of all preceding 
glyph infos
-                       // on the current/last line
-                       // * Adjust the baseline offset according to the max 
ascent
-                       // * Fill in the line index.
-                       unsigned lineEnd;
-                       if (lineBreak)
-                               lineEnd = i;
-                       else
-                               lineEnd = i - 1;
-
-                       float lineHeight = 0.0;
-                       _FinalizeLine(lineStart, lineEnd, lineIndex, y,
-                               lineHeight);
-
-                       // Start position of the next line
-                       x = fLineInset;
-                       y += lineHeight + fLineSpacing;
-
-                       if (lineBreak)
-                               lineStart = i + 1;
-                       else
-                               lineStart = i;
-
-                       lineIndex++;
-               }
-
-               if (!lineBreak && i < fGlyphInfoCount) {
-                       fGlyphInfoBuffer[i].x = x;
-                       fGlyphInfoBuffer[i].y = y;
-               }
-
-               x += advanceX;
-               y += advanceY;
-       }
-
-       // The last line may not have been appended and initialized yet.
-       if (lineStart <= fGlyphInfoCount - 1) {
-               float lineHeight;
-               _FinalizeLine(lineStart, fGlyphInfoCount - 1, lineIndex, y, 
lineHeight);
-       }
-}
-
-
-void
-TextLayout::_GetGlyphAdvance(int offset, float& advanceX, float& advanceY,
-       float escapementArray[]) const
-{
-       float additionalGlyphSpacing = 0.0f;
-       if (fGlyphInfoBuffer[offset].style.Get() != NULL)
-               additionalGlyphSpacing = 
fGlyphInfoBuffer[offset].style->glyphSpacing;
-       else
-               additionalGlyphSpacing = fGlyphSpacing;
-
-       if (fGlyphInfoBuffer[offset].style.Get() != NULL
-               && fGlyphInfoBuffer[offset].style->width > 0.0f) {
-               // Use the metrics provided by the TextStyle
-               advanceX = fGlyphInfoBuffer[offset].style->width
-                       + additionalGlyphSpacing;
-       } else {
-               advanceX = escapementArray[offset] + additionalGlyphSpacing;
-               advanceY = 0.0f;
-       }
-}
-
-
-void
-TextLayout::_FinalizeLine(int lineStart, int lineEnd, int lineIndex, float y,
-       float& lineHeight)
-{
-       lineHeight = 0.0f;
-       float maxAscent = 0.0f;
-       float maxDescent = 0.0f;
-
-       for (int i = lineStart; i <= lineEnd; i++) {
-               if (fGlyphInfoBuffer[i].style.Get() != NULL) {
-                       if (fGlyphInfoBuffer[i].style->font.Size() > lineHeight)
-                               lineHeight = 
fGlyphInfoBuffer[i].style->font.Size();
-                       if (fGlyphInfoBuffer[i].style->ascent > maxAscent)
-                               maxAscent = fGlyphInfoBuffer[i].style->ascent;
-                       if (fGlyphInfoBuffer[i].style->descent > maxDescent)
-                               maxDescent = fGlyphInfoBuffer[i].style->descent;
-               } else {
-                       if (fDefaultFont.Size() > lineHeight)
-                               lineHeight = fDefaultFont.Size();
-                       if (fAscent > maxAscent)
-                               maxAscent = fAscent;
-                       if (fDescent > maxDescent)
-                               maxDescent = fDescent;
-               }
-       }
-
-       fLineInfos.Add(LineInfo(lineStart, y, lineHeight, maxAscent, 
maxDescent));
-
-       for (int i = lineStart; i <= lineEnd; i++) {
-               fGlyphInfoBuffer[i].maxAscent = maxAscent;
-               fGlyphInfoBuffer[i].maxDescent = maxDescent;
-               fGlyphInfoBuffer[i].lineIndex = lineIndex;
-               fGlyphInfoBuffer[i].y += maxAscent;
-       }
-}
diff --git a/src/apps/haiku-depot/textview/TextLayout.h 
b/src/apps/haiku-depot/textview/TextLayout.h
deleted file mode 100644
index 05058b9..0000000
--- a/src/apps/haiku-depot/textview/TextLayout.h
+++ /dev/null
@@ -1,85 +0,0 @@
-/*
- * Copyright 2013, Stephan Aßmus <superstippi@xxxxxx>.
- * All rights reserved. Distributed under the terms of the MIT License.
- */
-#ifndef TEXT_LAYOUT_H
-#define TEXT_LAYOUT_H
-
-#include <Font.h>
-#include <Referenceable.h>
-#include <String.h>
-
-#include "GlyphInfo.h"
-#include "LineInfo.h"
-
-
-class BView;
-
-
-class TextLayout : public BReferenceable {
-public:
-                                                               TextLayout();
-                                                               
TextLayout(const TextLayout& other);
-       virtual                                         ~TextLayout();
-
-                       void                            SetText(const BString& 
text);
-                       const BString&          Text() const
-                                                                       { 
return fText; }
-
-                       void                            SetFont(const BFont& 
font);
-                       const BFont&            Font() const
-                                                                       { 
return fDefaultFont; }
-
-                       void                            SetGlyphSpacing(float 
glyphSpacing);
-                       float                           GlyphSpacing() const
-                                                                       { 
return fGlyphSpacing; }
-
-                       void                            SetFirstLineInset(float 
inset);
-                       float                           FirstLineInset() const
-                                                                       { 
return fFirstLineInset; }
-
-                       void                            SetLineInset(float 
inset);
-                       float                           LineInset() const
-                                                                       { 
return fLineInset; }
-
-                       void                            SetLineSpacing(float 
spacing);
-                       float                           LineSpacing() const
-                                                                       { 
return fLineSpacing; }
-
-                       void                            SetWidth(float width);
-                       float                           Width() const
-                                                                       { 
return fWidth; }
-
-                       float                           Height();
-                       void                            Draw(BView* view, const 
BPoint& offset);
-
-private:
-                       void                            _ValidateLayout();
-                       void                            _Layout();
-                       void                            _GetGlyphAdvance(int 
offset,
-                                                                       float& 
advanceX, float& advanceY,
-                                                                       float 
escapementArray[]) const;
-                       
-                       void                            _FinalizeLine(int 
lineStart, int lineEnd,
-                                                                       int 
lineIndex, float y, float& lineHeight);
-private:
-                       BString                         fText;
-
-                       BFont                           fDefaultFont;
-                       float                           fAscent;
-                       float                           fDescent;
-                       float                           fWidth;
-                       float                           fGlyphSpacing;
-                       float                           fFirstLineInset;
-                       float                           fLineInset;
-                       float                           fLineSpacing;
-                       
-                       bool                            fLayoutValid;
-
-                       GlyphInfo*                      fGlyphInfoBuffer;
-                       int                                     fGlyphInfoCount;
-                       LineInfoList            fLineInfos;
-
-};
-
-#endif // TEXT_LAYOUT_H
diff --git a/src/apps/haiku-depot/textview/TextStyle.cpp 
b/src/apps/haiku-depot/textview/TextStyle.cpp
deleted file mode 100644
index a96ccb1..0000000
--- a/src/apps/haiku-depot/textview/TextStyle.cpp
+++ /dev/null
@@ -1,97 +0,0 @@
-/*
- * Copyright 2013, Stephan Aßmus <superstippi@xxxxxx>.
- * All rights reserved. Distributed under the terms of the MIT License.
- */
-
-#include "TextStyle.h"
-
-
-TextStyle::TextStyle()
-       :
-       font(),
-
-       ascent(0.0f),
-       descent(0.0f),
-       width(-1.0f),
-       glyphSpacing(0.0f),
-
-       fgColor((rgb_color){ 0, 0, 0, 255 }),
-       bgColor((rgb_color){ 255, 255, 255, 255 }),
-
-       strikeOut(false),
-       strikeOutColor((rgb_color){ 0, 0, 0, 255 }),
-
-       underline(false),
-       underlineStyle(0),
-       underlineColor((rgb_color){ 0, 0, 0, 255 })
-{
-}
-
-
-TextStyle::TextStyle(const BFont& font, float ascent, float descent,
-               float width, float glyphSpacing, rgb_color fgColor, rgb_color 
bgColor,
-               bool strikeOut, rgb_color strikeOutColor, bool underline,
-               uint32 underlineStyle, rgb_color underlineColor)
-       :
-       font(font),
-
-       ascent(ascent),
-       descent(descent),
-       width(width),
-       glyphSpacing(glyphSpacing),
-
-       fgColor(fgColor),
-       bgColor(bgColor),
-
-       strikeOut(strikeOut),
-       strikeOutColor(strikeOutColor),
-
-       underline(underline),
-       underlineStyle(underlineStyle),
-       underlineColor(underlineColor)
-{
-}
-
-
-TextStyle::TextStyle(const TextStyle& other)
-       :
-       font(other.font),
-
-       ascent(other.ascent),
-       descent(other.descent),
-       width(other.width),
-       glyphSpacing(other.glyphSpacing),
-
-       fgColor(other.fgColor),
-       bgColor(other.bgColor),
-
-       strikeOut(other.strikeOut),
-       strikeOutColor(other.strikeOutColor),
-
-       underline(other.underline),
-       underlineStyle(other.underlineStyle),
-       underlineColor(other.underlineColor)
-{
-}
-
-
-bool
-TextStyle::operator==(const TextStyle& other) const
-{
-       return font == other.font
-
-               && ascent == other.ascent
-               && descent == other.descent
-               && width == other.width
-               && glyphSpacing == other.glyphSpacing
-
-               && fgColor == other.fgColor
-               && bgColor == other.bgColor
-               
-               && strikeOut == other.strikeOut
-               && strikeOutColor == other.strikeOutColor
-               
-               && underline == other.underline
-               && underlineStyle == other.underlineStyle
-               && underlineColor == other.underlineColor;
-}
diff --git a/src/apps/haiku-depot/textview/TextStyle.h 
b/src/apps/haiku-depot/textview/TextStyle.h
deleted file mode 100644
index 5f6643e..0000000
--- a/src/apps/haiku-depot/textview/TextStyle.h
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
- * Copyright 2013, Stephan Aßmus <superstippi@xxxxxx>.
- * All rights reserved. Distributed under the terms of the MIT License.
- */
-#ifndef TEXT_STYLE_H
-#define TEXT_STYLE_H
-
-#include <Font.h>
-#include <GraphicsDefs.h>
-#include <Referenceable.h>
-
-
-class TextStyle : public BReferenceable {
-public:
-       TextStyle();
-       TextStyle(const BFont& font, float ascent, float descent, float width,
-               float glyphSpacing,
-               rgb_color fgColor, rgb_color bgColor, bool strikeOut,
-               rgb_color strikeOutColor, bool underline,
-               uint32 underlineStyle, rgb_color underlineColor);
-
-       TextStyle(const TextStyle& other);
-
-       bool operator==(const TextStyle& other) const;
-
-public:
-       BFont                                   font;
-
-       // The following three values override glyph metrics unless -1
-       float                                   ascent;
-       float                                   descent;
-       float                                   width;
-       float                                   glyphSpacing;
-
-       rgb_color                               fgColor;
-       rgb_color                               bgColor;
-
-       bool                                    strikeOut;
-       rgb_color                               strikeOutColor;
-
-       bool                                    underline;
-       uint32                                  underlineStyle;
-       rgb_color                               underlineColor;
-};
-
-
-typedef BReference<TextStyle> TextStyleRef;
-
-
-#endif // TEXT_STYLE_H


Other related posts:

  • » [haiku-commits] haiku: hrev46024 - src/apps/haiku-depot/textview - superstippi