180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru/* 380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * Copyright 2006 The Android Open Source Project 480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * 580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * Use of this source code is governed by a BSD-style license that can be 680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * found in the LICENSE file. 780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru */ 880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 1080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#include "SkDrawTextBox.h" 1180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#include "SkAnimateMaker.h" 1280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#include "SkCanvas.h" 1380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#include "SkPaint.h" 1480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 1580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queruenum SkDrawTextBox_Properties { 1680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru foo = 100, 1780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru SK_PROPERTY(spacingAlign), 1880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru SK_PROPERTY(mode) 1980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru}; 2080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 2180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 2280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#if SK_USE_CONDENSED_INFO == 0 2380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 2480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queruconst SkMemberInfo SkDrawTextBox::fInfo[] = { 2580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru SK_MEMBER_INHERITED, 2680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru SK_MEMBER(mode, TextBoxMode), 2780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru SK_MEMBER_ALIAS(spacingAdd, fSpacingAdd, Float), 2880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru SK_MEMBER(spacingAlign, TextBoxAlign), 2980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru SK_MEMBER_ALIAS(spacingMul, fSpacingMul, Float), 3080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru SK_MEMBER_ALIAS(text, fText, String) 3180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru}; 3280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 3380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#endif 3480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 3580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste QueruDEFINE_GET_MEMBER(SkDrawTextBox); 3680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 3780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste QueruSkDrawTextBox::SkDrawTextBox() 3880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru{ 3980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru fSpacingMul = SK_Scalar1; 4080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru fSpacingAdd = 0; 4180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru spacingAlign = SkTextBox::kStart_SpacingAlign; 4280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru mode = SkTextBox::kLineBreak_Mode; 4380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru} 4480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 4580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#ifdef SK_DUMP_ENABLED 4680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queruvoid SkDrawTextBox::dump(SkAnimateMaker* maker) 4780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru{ 4880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru dumpBase(maker); 4980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru dumpAttrs(maker); 5080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru if (mode == 0) 5180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru SkDebugf("mode=\"oneLine\" "); 5280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru if (spacingAlign == 1) 5380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru SkDebugf("spacingAlign=\"center\" "); 5480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru else if (spacingAlign == 2) 5580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru SkDebugf("spacingAlign=\"end\" "); 5680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru SkDebugf("/>\n"); 5780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru} 5880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#endif 5980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 6080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Querubool SkDrawTextBox::getProperty(int index, SkScriptValue* value) const 6180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru{ 6280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru return this->INHERITED::getProperty(index, value); 6380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru} 6480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 6580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Querubool SkDrawTextBox::setProperty(int index, SkScriptValue& scriptValue) 6680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru{ 6780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru return this->INHERITED::setProperty(index, scriptValue); 6880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru} 6980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 7080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Querubool SkDrawTextBox::draw(SkAnimateMaker& maker) 7180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru{ 7280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru SkTextBox box; 7380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru box.setMode((SkTextBox::Mode) mode); 7480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru box.setSpacingAlign((SkTextBox::SpacingAlign) spacingAlign); 7580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru box.setBox(fRect); 7680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru box.setSpacing(fSpacingMul, fSpacingAdd); 7780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru SkBoundableAuto boundable(this, maker); 7880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru box.draw(maker.fCanvas, fText.c_str(), fText.size(), *maker.fPaint); 7980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru return false; 8080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru} 81