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