1 /* 2 * Copyright 2001-2006, Haiku, Inc. All Rights Reserved. 3 * Distributed under the terms of the MIT License. 4 * 5 * Authors: 6 * Marc Flerackers (mflerackers@androme.be) 7 * Stefano Ceccherini (burton666@libero.it) 8 */ 9 10 11 #include <Font.h> 12 #include <InterfaceDefs.h> 13 #include <SupportDefs.h> 14 #include <TextView.h> 15 16 #include "TextViewSupportBuffer.h" 17 18 19 struct STEStyle { 20 BFont font; // font 21 rgb_color color; // pen color 22 }; 23 24 25 struct STEStyleRun { 26 long offset; // byte offset of first character of run 27 STEStyle style; // style info 28 }; 29 30 31 struct STEStyleRange { 32 long count; // number of style runs 33 STEStyleRun runs[1]; // array of count number of runs 34 }; 35 36 37 struct STEStyleRecord { 38 long refs; // reference count for this style 39 float ascent; // ascent for this style 40 float descent; // descent for this style 41 STEStyle style; // style info 42 }; 43 44 45 struct STEStyleRunDesc { 46 long offset; // byte offset of first character of run 47 long index; // index of corresponding style record 48 }; 49 50 51 // _BStyleRunDescBuffer_ class ------------------------------------------------- 52 class _BStyleRunDescBuffer_ : public _BTextViewSupportBuffer_<STEStyleRunDesc> { 53 public: 54 _BStyleRunDescBuffer_(); 55 56 void InsertDesc(STEStyleRunDesc* inDesc, int32 index); 57 void RemoveDescs(int32 index, int32 count = 1); 58 59 int32 OffsetToRun(int32 offset) const; 60 void BumpOffset(int32 delta, int32 index); 61 62 STEStyleRunDesc* operator[](int32 index) const; 63 }; 64 65 66 inline STEStyleRunDesc* 67 _BStyleRunDescBuffer_::operator[](int32 index) const 68 { 69 return &fBuffer[index]; 70 } 71 72 73 // _BStyleRecordBuffer_ class -------------------------------------------------- 74 class _BStyleRecordBuffer_ : public _BTextViewSupportBuffer_<STEStyleRecord> { 75 public: 76 _BStyleRecordBuffer_(); 77 78 int32 InsertRecord(const BFont *inFont, const rgb_color *inColor); 79 void CommitRecord(int32 index); 80 void RemoveRecord(int32 index); 81 82 bool MatchRecord(const BFont *inFont, const rgb_color *inColor, 83 int32 *outIndex); 84 85 STEStyleRecord* operator[](int32 index) const; 86 }; 87 88 89 inline STEStyleRecord* 90 _BStyleRecordBuffer_::operator[](int32 index) const 91 { 92 return &fBuffer[index]; 93 } 94 95 96 // StyleBuffer class -------------------------------------------------------- 97 class BTextView::StyleBuffer { 98 public: 99 StyleBuffer(const BFont *inFont, 100 const rgb_color *inColor); 101 102 void InvalidateNullStyle(); 103 bool IsValidNullStyle() const; 104 105 void SyncNullStyle(int32 offset); 106 void SetNullStyle(uint32 inMode, const BFont *inFont, 107 const rgb_color *inColor, int32 offset = 0); 108 void GetNullStyle(const BFont **font, 109 const rgb_color **color) const; 110 111 void GetStyle(int32 inOffset, BFont *outFont, 112 rgb_color *outColor) const; 113 void ContinuousGetStyle(BFont *, uint32 *, rgb_color *, 114 bool *, int32, int32) const; 115 116 STEStyleRange* AllocateStyleRange(const int32 numStyles) const; 117 void SetStyleRange(int32 fromOffset, int32 toOffset, 118 int32 textLen, uint32 inMode, 119 const BFont *inFont, const rgb_color *inColor); 120 STEStyleRange* GetStyleRange(int32 startOffset, 121 int32 endOffset) const; 122 123 void RemoveStyleRange(int32 fromOffset, int32 toOffset); 124 void RemoveStyles(int32 index, int32 count = 1); 125 126 int32 Iterate(int32 fromOffset, int32 length, 127 InlineInput* input, 128 const BFont **outFont = NULL, 129 const rgb_color **outColor = NULL, 130 float *outAscent = NULL, 131 float *outDescen = NULL, uint32 * = NULL) const; 132 133 int32 OffsetToRun(int32 offset) const; 134 void BumpOffset(int32 delta, int32 index); 135 136 STEStyleRun operator[](int32 index) const; 137 int32 NumRuns() const; 138 139 const _BStyleRunDescBuffer_& RunBuffer() const; 140 const _BStyleRecordBuffer_& RecordBuffer() const; 141 142 private: 143 _BStyleRunDescBuffer_ fStyleRunDesc; 144 _BStyleRecordBuffer_ fStyleRecord; 145 bool fValidNullStyle; 146 STEStyle fNullStyle; 147 }; 148 149 150 inline int32 151 BTextView::StyleBuffer::NumRuns() const 152 { 153 return fStyleRunDesc.ItemCount(); 154 } 155 156 157 inline const _BStyleRunDescBuffer_& 158 BTextView::StyleBuffer::RunBuffer() const 159 { 160 return fStyleRunDesc; 161 } 162 163 164 inline const _BStyleRecordBuffer_& 165 BTextView::StyleBuffer::RecordBuffer() const 166 { 167 return fStyleRecord; 168 } 169