From 0f7100439030a319d8611b5bc8e1a05316bb0e1b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20A=C3=9Fmus?= Date: Tue, 13 Aug 2013 00:34:45 +0200 Subject: [PATCH] HaikuDepot: More work on custom TextView * TextLayout produces some first visible results... --- src/apps/haiku-depot/Jamfile | 1 + src/apps/haiku-depot/PackageInfoView.cpp | 10 +- src/apps/haiku-depot/textview/GlyphInfo.h | 100 +++ src/apps/haiku-depot/textview/LineInfo.h | 80 +++ src/apps/haiku-depot/textview/TextLayout.cpp | 604 ++++++++++--------- src/apps/haiku-depot/textview/TextLayout.h | 40 +- src/apps/haiku-depot/textview/TextStyle.cpp | 31 + src/apps/haiku-depot/textview/TextStyle.h | 45 ++ src/apps/haiku-depot/textview/TextView.cpp | 10 +- src/apps/haiku-depot/textview/TextView.h | 2 +- 10 files changed, 627 insertions(+), 296 deletions(-) create mode 100644 src/apps/haiku-depot/textview/GlyphInfo.h create mode 100644 src/apps/haiku-depot/textview/LineInfo.h create mode 100644 src/apps/haiku-depot/textview/TextStyle.cpp create mode 100644 src/apps/haiku-depot/textview/TextStyle.h diff --git a/src/apps/haiku-depot/Jamfile b/src/apps/haiku-depot/Jamfile index 4a548446b6..4fca5680d0 100644 --- a/src/apps/haiku-depot/Jamfile +++ b/src/apps/haiku-depot/Jamfile @@ -25,6 +25,7 @@ Application HaikuDepot : support.cpp TextLayout.cpp + TextStyle.cpp TextView.cpp : be translation libcolumnlistview.a libshared.a $(TARGET_LIBSUPC++) diff --git a/src/apps/haiku-depot/PackageInfoView.cpp b/src/apps/haiku-depot/PackageInfoView.cpp index d91589e1d5..1a6eb14819 100644 --- a/src/apps/haiku-depot/PackageInfoView.cpp +++ b/src/apps/haiku-depot/PackageInfoView.cpp @@ -22,6 +22,7 @@ #include #include "PackageManager.h" +#include "TextView.h" #undef B_TRANSLATION_CONTEXT @@ -733,12 +734,11 @@ public: fPackageVersionView->SetFont(&versionFont); fPackageVersionView->SetHighColor(kLightBlack); - fTextView = new BTextView("rating text"); + fTextView = new TextView("rating text"); fTextView->SetViewColor(ViewColor()); - fTextView->MakeEditable(false); fTextView->SetText(rating.Comment()); - const float textInset = be_plain_font->Size(); - fTextView->SetInsets(0.0f, floorf(textInset / 2), textInset, 0.0f); +// const float textInset = be_plain_font->Size(); +// fTextView->SetInsets(0.0f, floorf(textInset / 2), textInset, 0.0f); BLayoutBuilder::Group<>(this) .Add(fAvatarView, 0.2f) @@ -763,7 +763,7 @@ private: RatingView* fRatingView; BStringView* fRatingLabelView; BStringView* fPackageVersionView; - BTextView* fTextView; + TextView* fTextView; }; diff --git a/src/apps/haiku-depot/textview/GlyphInfo.h b/src/apps/haiku-depot/textview/GlyphInfo.h new file mode 100644 index 0000000000..00211b7b64 --- /dev/null +++ b/src/apps/haiku-depot/textview/GlyphInfo.h @@ -0,0 +1,100 @@ +/* + * Copyright 2013, Stephan Aßmus . + * 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), + maxAscend(0.0f), + maxDescend(0.0f), + lineIndex(0), + style() + { + } + + GlyphInfo(uint32 charCode, float x, float y, float advanceX, + float maxAscend, float maxDescend, int lineIndex, + const TextStyleRef& style) + : + charCode(charCode), + x(x), + y(y), + advanceX(advanceX), + maxAscend(maxAscend), + maxDescend(maxDescend), + lineIndex(lineIndex), + style(style) + { + } + + GlyphInfo(const GlyphInfo& other) + : + charCode(other.charCode), + x(other.x), + y(other.y), + advanceX(other.advanceX), + maxAscend(other.maxAscend), + maxDescend(other.maxDescend), + lineIndex(other.lineIndex), + style(other.style) + { + } + + GlyphInfo& operator=(const GlyphInfo& other) + { + charCode = other.charCode; + x = other.x; + y = other.y; + advanceX = other.advanceX; + maxAscend = other.maxAscend; + maxDescend = other.maxDescend; + 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 + && maxAscend == other.maxAscend + && maxDescend == other.maxDescend + && 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 maxAscend; + float maxDescend; + + 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 new file mode 100644 index 0000000000..4d41c8231b --- /dev/null +++ b/src/apps/haiku-depot/textview/LineInfo.h @@ -0,0 +1,80 @@ +/* + * Copyright 2013, Stephan Aßmus . + * 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 LineInfoList; + + +#endif // LINE_INFO_H diff --git a/src/apps/haiku-depot/textview/TextLayout.cpp b/src/apps/haiku-depot/textview/TextLayout.cpp index 6ce034289d..6434dab889 100644 --- a/src/apps/haiku-depot/textview/TextLayout.cpp +++ b/src/apps/haiku-depot/textview/TextLayout.cpp @@ -6,12 +6,15 @@ #include "TextLayout.h" #include +#include #include #include #include +#include "GlyphInfo.h" #include "List.h" +#include "TextStyle.h" enum { @@ -26,7 +29,7 @@ enum { }; -static uint32 +inline uint32 get_char_classification(uint32 charCode) { // TODO: Should check against a list of characters containing also @@ -87,185 +90,6 @@ get_char_classification(uint32 charCode) } -class Style : public BReferenceable { -public: - Style(const BFont& font, float ascent, float descent, float width, - 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), - - fgColor(fgColor), - bgColor(bgColor), - - strikeOut(strikeOut), - strikeOutColor(strikeOutColor), - - underline(underline), - underlineStyle(underlineStyle), - underlineColor(underlineColor) - { - } - -public: - BFont font; - - // The following three values override glyph metrics unless -1 - float ascent; - float descent; - float width; - - rgb_color fgColor; - rgb_color bgColor; - - bool strikeOut; - rgb_color strikeOutColor; - - bool underline; - uint32 underlineStyle; - rgb_color underlineColor; -}; - - -typedef BReference