00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036 #ifndef RECT_HXX
00037 #define RECT_HXX
00038
00039 #include <new>
00040
00041
00042 #ifndef _GEN_HXX //autogen
00043 #include <tools/gen.hxx>
00044 #endif
00045
00046 #ifndef _SV_OUTDEV_HXX //autogen
00047 #include <vcl/outdev.hxx>
00048 #endif
00049
00050 #ifndef _SV_METRIC_HXX //autogen
00051 #include <vcl/metric.hxx>
00052 #endif
00053
00054 #ifndef _TOOLS_DEBUG_HXX //autogen
00055 #include <tools/debug.hxx>
00056 #endif
00057
00058 #include "format.hxx"
00059
00060
00061 BOOL SmGetGlyphBoundRect(const OutputDevice &rDev,
00062 const XubString &rText, Rectangle &rRect);
00063
00064 BOOL SmIsMathAlpha(const XubString &rText);
00065
00066
00067 inline long SmFromTo(long nFrom, long nTo, double fRelDist)
00068 {
00069 return nFrom + (long) (fRelDist * (nTo - nFrom));
00070 }
00071
00072
00074
00075
00076
00077
00078
00079
00080
00081
00082 #define SM_RECT_CORE 0x0001
00083 #define SM_RECT_ITALIC 0x0002
00084 #define SM_RECT_LINES 0x0004
00085 #define SM_RECT_MID 0x0008
00086
00087
00088 enum RectPos
00089
00090 { RP_LEFT, RP_RIGHT,
00091 RP_TOP, RP_BOTTOM,
00092 RP_ATTRIBUT
00093 };
00094 enum RectHorAlign
00095 { RHA_LEFT, RHA_CENTER, RHA_RIGHT
00096 };
00097 enum RectVerAlign
00098 { RVA_TOP, RVA_MID, RVA_BOTTOM, RVA_BASELINE, RVA_CENTERY,
00099 RVA_ATTRIBUT_HI, RVA_ATTRIBUT_MID, RVA_ATTRIBUT_LO
00100 };
00101
00102
00103 enum RectCopyMBL
00104 { RCP_THIS,
00105 RCP_ARG,
00106 RCP_NONE,
00107 RCP_XOR
00108
00109 };
00110
00111
00112 class SmRect
00113 {
00114 Point aTopLeft;
00115 Size aSize;
00116 long nBaseline,
00117 nAlignT,
00118 nAlignM,
00119 nAlignB,
00120 nGlyphTop,
00121 nGlyphBottom,
00122 nItalicLeftSpace,
00123 nItalicRightSpace,
00124 nLoAttrFence,
00125 nHiAttrFence;
00126 USHORT nBorderWidth;
00127 BOOL bHasBaseline,
00128 bHasAlignInfo;
00129
00130 protected:
00131 void BuildRect (const OutputDevice &rDev, const SmFormat *pFormat,
00132 const XubString &rText, USHORT nBorderWidth);
00133 void Init(const OutputDevice &rDev, const SmFormat *pFormat,
00134 const XubString &rText, USHORT nBorderWidth);
00135
00136 void ClearBaseline() { bHasBaseline = FALSE; };
00137 inline void CopyMBL(const SmRect& rRect);
00138 void CopyAlignInfo(const SmRect& rRect);
00139
00140 SmRect & Union(const SmRect &rRect);
00141
00142 public:
00143 SmRect();
00144 SmRect(const OutputDevice &rDev, const SmFormat *pFormat,
00145 const XubString &rText, long nBorderWidth);
00146 SmRect(long nWidth, long nHeight);
00147 SmRect(const SmRect &rRect);
00148
00149
00150 USHORT GetBorderWidth() const { return nBorderWidth; }
00151
00152 void SetItalicSpaces(long nLeftSpace, long nRightSpace);
00153
00154 void SetWidth(ULONG nWidth) { aSize.Width() = nWidth; }
00155 void SetHeight(ULONG nHeight) { aSize.Height() = nHeight; }
00156
00157 void SetLeft(long nLeft);
00158 void SetRight(long nRight);
00159 void SetBottom(long nBottom);
00160 void SetTop(long nTop);
00161
00162 const Point & GetTopLeft() const { return aTopLeft; }
00163
00164 long GetTop() const { return GetTopLeft().Y(); }
00165 long GetLeft() const { return GetTopLeft().X(); }
00166 long GetBottom() const { return GetTop() + GetHeight() - 1; }
00167 long GetRight() const { return GetLeft() + GetWidth() - 1; }
00168 long GetCenterX() const { return (GetLeft() + GetRight()) / 2L; }
00169 long GetCenterY() const { return (GetTop() + GetBottom()) / 2L; }
00170 long GetWidth() const { return GetSize().Width(); }
00171 long GetHeight() const { return GetSize().Height(); }
00172
00173 long GetItalicLeftSpace() const { return nItalicLeftSpace; }
00174 long GetItalicRightSpace() const { return nItalicRightSpace; }
00175
00176 void SetHiAttrFence(long nVal) { nHiAttrFence = nVal; }
00177 void SetLoAttrFence(long nVal) { nLoAttrFence = nVal; }
00178 long GetHiAttrFence() const { return nHiAttrFence; }
00179 long GetLoAttrFence() const { return nLoAttrFence; }
00180
00181 long GetItalicLeft() const { return GetLeft() - GetItalicLeftSpace(); }
00182 long GetItalicCenterX() const { return (GetItalicLeft() + GetItalicRight()) / 2; }
00183 long GetItalicRight() const { return GetRight() + GetItalicRightSpace(); }
00184 long GetItalicWidth() const { return GetWidth() + GetItalicLeftSpace() + GetItalicRightSpace(); }
00185
00186 BOOL HasBaseline() const { return bHasBaseline; }
00187 inline long GetBaseline() const;
00188 long GetBaselineOffset() const { return GetBaseline() - GetTop(); }
00189
00190 void SetAlignTop(long nVal) { nAlignT = nVal; }
00191
00192 long GetAlignT() const { return nAlignT; }
00193 long GetAlignM() const { return nAlignM; }
00194 long GetAlignB() const { return nAlignB; }
00195
00196 void SetAlignT(long nVal) { nAlignT = nVal; }
00197
00198 const Point GetCenter() const
00199 { return Point(GetCenterX(), GetCenterY()); }
00200
00201 const Size & GetSize() const { return aSize; }
00202
00203 const Size GetItalicSize() const
00204 { return Size(GetItalicWidth(), GetHeight()); }
00205
00206 void Move (const Point &rPosition);
00207 void MoveTo(const Point &rPosition) { Move(rPosition - GetTopLeft()); }
00208
00209 BOOL IsEmpty() const
00210 {
00211 return GetWidth() == 0 || GetHeight() == 0;
00212 }
00213
00214 BOOL HasAlignInfo() const { return bHasAlignInfo; }
00215
00216 const Point AlignTo(const SmRect &rRect, RectPos ePos,
00217 RectHorAlign eHor, RectVerAlign eVer) const;
00218
00219 SmRect & ExtendBy(const SmRect &rRect, RectCopyMBL eCopyMode);
00220 SmRect & ExtendBy(const SmRect &rRect, RectCopyMBL eCopyMode,
00221 long nNewAlignM);
00222 SmRect & ExtendBy(const SmRect &rRect, RectCopyMBL eCopyMode,
00223 BOOL bKeepVerAlignParams);
00224
00225 long OrientedDist(const Point &rPoint) const;
00226 BOOL IsInsideRect(const Point &rPoint) const;
00227 BOOL IsInsideItalicRect(const Point &rPoint) const;
00228
00229 inline SmRect & operator = (const SmRect &rRect);
00230
00231 inline Rectangle AsRectangle() const;
00232 SmRect AsGlyphRect() const;
00233
00234 void Draw(OutputDevice &rDev, const Point &rPosition, int nFlags) const;
00235 };
00236
00237
00238 inline void SmRect::SetItalicSpaces(long nLeftSpace, long nRightSpace)
00239
00240
00241 {
00242 nItalicLeftSpace = nLeftSpace;
00243 nItalicRightSpace = nRightSpace;
00244 }
00245
00246
00247 inline void SmRect::CopyMBL(const SmRect &rRect)
00248
00249 {
00250 nBaseline = rRect.nBaseline;
00251 bHasBaseline = rRect.bHasBaseline;
00252 nAlignM = rRect.nAlignM;
00253 }
00254
00255
00256 inline long SmRect::GetBaseline() const
00257 {
00258 DBG_ASSERT(HasBaseline(), "Sm: Baseline nicht vorhanden");
00259 return nBaseline;
00260 }
00261
00262
00263 inline SmRect & SmRect::operator = (const SmRect &rRect)
00264 {
00265 new (this) SmRect(rRect);
00266 return *this;
00267 }
00268
00269
00270 inline Rectangle SmRect::AsRectangle() const
00271 {
00272 return Rectangle(Point(GetItalicLeft(), GetTop()), GetItalicSize());
00273 }
00274
00275
00276
00277 #endif