1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/gfx/skia/trunk/include/views/SkTextBox.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,77 @@ 1.4 + 1.5 +/* 1.6 + * Copyright 2006 The Android Open Source Project 1.7 + * 1.8 + * Use of this source code is governed by a BSD-style license that can be 1.9 + * found in the LICENSE file. 1.10 + */ 1.11 + 1.12 + 1.13 +#ifndef SkTextBox_DEFINED 1.14 +#define SkTextBox_DEFINED 1.15 + 1.16 +#include "SkCanvas.h" 1.17 + 1.18 +/** \class SkTextBox 1.19 + 1.20 + SkTextBox is a helper class for drawing 1 or more lines of text 1.21 + within a rectangle. The textbox is positioned and clipped by its Frame. 1.22 + The Margin rectangle controls where the text is drawn relative to 1.23 + the Frame. Line-breaks occur inside the Margin rectangle. 1.24 + 1.25 + Spacing is a linear equation used to compute the distance between lines 1.26 + of text. Spacing consists of two scalars: mul and add, and the spacing 1.27 + between lines is computed as: spacing = paint.getTextSize() * mul + add 1.28 +*/ 1.29 +class SkTextBox { 1.30 +public: 1.31 + SkTextBox(); 1.32 + 1.33 + enum Mode { 1.34 + kOneLine_Mode, 1.35 + kLineBreak_Mode, 1.36 + 1.37 + kModeCount 1.38 + }; 1.39 + Mode getMode() const { return (Mode)fMode; } 1.40 + void setMode(Mode); 1.41 + 1.42 + enum SpacingAlign { 1.43 + kStart_SpacingAlign, 1.44 + kCenter_SpacingAlign, 1.45 + kEnd_SpacingAlign, 1.46 + 1.47 + kSpacingAlignCount 1.48 + }; 1.49 + SpacingAlign getSpacingAlign() const { return (SpacingAlign)fSpacingAlign; } 1.50 + void setSpacingAlign(SpacingAlign); 1.51 + 1.52 + void getBox(SkRect*) const; 1.53 + void setBox(const SkRect&); 1.54 + void setBox(SkScalar left, SkScalar top, SkScalar right, SkScalar bottom); 1.55 + 1.56 + void getSpacing(SkScalar* mul, SkScalar* add) const; 1.57 + void setSpacing(SkScalar mul, SkScalar add); 1.58 + 1.59 + void draw(SkCanvas*, const char text[], size_t len, const SkPaint&); 1.60 + 1.61 + void setText(const char text[], size_t len, const SkPaint&); 1.62 + void draw(SkCanvas*); 1.63 + int countLines() const; 1.64 + SkScalar getTextHeight() const; 1.65 + 1.66 +private: 1.67 + SkRect fBox; 1.68 + SkScalar fSpacingMul, fSpacingAdd; 1.69 + uint8_t fMode, fSpacingAlign; 1.70 + const char* fText; 1.71 + size_t fLen; 1.72 + const SkPaint* fPaint; 1.73 +}; 1.74 + 1.75 +class SkTextLineBreaker { 1.76 +public: 1.77 + static int CountLines(const char text[], size_t len, const SkPaint&, SkScalar width); 1.78 +}; 1.79 + 1.80 +#endif