michael@0: michael@0: /* michael@0: * Copyright 2006 The Android Open Source Project michael@0: * michael@0: * Use of this source code is governed by a BSD-style license that can be michael@0: * found in the LICENSE file. michael@0: */ michael@0: michael@0: michael@0: #ifndef SkTextBox_DEFINED michael@0: #define SkTextBox_DEFINED michael@0: michael@0: #include "SkCanvas.h" michael@0: michael@0: /** \class SkTextBox michael@0: michael@0: SkTextBox is a helper class for drawing 1 or more lines of text michael@0: within a rectangle. The textbox is positioned and clipped by its Frame. michael@0: The Margin rectangle controls where the text is drawn relative to michael@0: the Frame. Line-breaks occur inside the Margin rectangle. michael@0: michael@0: Spacing is a linear equation used to compute the distance between lines michael@0: of text. Spacing consists of two scalars: mul and add, and the spacing michael@0: between lines is computed as: spacing = paint.getTextSize() * mul + add michael@0: */ michael@0: class SkTextBox { michael@0: public: michael@0: SkTextBox(); michael@0: michael@0: enum Mode { michael@0: kOneLine_Mode, michael@0: kLineBreak_Mode, michael@0: michael@0: kModeCount michael@0: }; michael@0: Mode getMode() const { return (Mode)fMode; } michael@0: void setMode(Mode); michael@0: michael@0: enum SpacingAlign { michael@0: kStart_SpacingAlign, michael@0: kCenter_SpacingAlign, michael@0: kEnd_SpacingAlign, michael@0: michael@0: kSpacingAlignCount michael@0: }; michael@0: SpacingAlign getSpacingAlign() const { return (SpacingAlign)fSpacingAlign; } michael@0: void setSpacingAlign(SpacingAlign); michael@0: michael@0: void getBox(SkRect*) const; michael@0: void setBox(const SkRect&); michael@0: void setBox(SkScalar left, SkScalar top, SkScalar right, SkScalar bottom); michael@0: michael@0: void getSpacing(SkScalar* mul, SkScalar* add) const; michael@0: void setSpacing(SkScalar mul, SkScalar add); michael@0: michael@0: void draw(SkCanvas*, const char text[], size_t len, const SkPaint&); michael@0: michael@0: void setText(const char text[], size_t len, const SkPaint&); michael@0: void draw(SkCanvas*); michael@0: int countLines() const; michael@0: SkScalar getTextHeight() const; michael@0: michael@0: private: michael@0: SkRect fBox; michael@0: SkScalar fSpacingMul, fSpacingAdd; michael@0: uint8_t fMode, fSpacingAlign; michael@0: const char* fText; michael@0: size_t fLen; michael@0: const SkPaint* fPaint; michael@0: }; michael@0: michael@0: class SkTextLineBreaker { michael@0: public: michael@0: static int CountLines(const char text[], size_t len, const SkPaint&, SkScalar width); michael@0: }; michael@0: michael@0: #endif