1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Mozilla MathML Project.
*
* The Initial Developer of the Original Code is
* The University Of Queensland.
* Portions created by the Initial Developer are Copyright (C) 1999
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Roger B. Sidje <rbs@maths.uq.edu.au>
* Shyjan Mahamud <mahamud@cs.cmu.edu>
* Karl Tomlinson <karlt+@karlt.net>, Mozilla Corporation
* Frederic Wang <fred.wang@free.fr>
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef nsMathMLChar_h___
#define nsMathMLChar_h___
#include "nsMathMLOperators.h"
#include "nsMathMLFrame.h"
class nsGlyphTable;
// Hints for Stretch() to indicate criteria for stretching
enum {
// Don't stretch
NS_STRETCH_NONE = 0x00,
// Variable size stretches
NS_STRETCH_VARIABLE_MASK = 0x0F,
NS_STRETCH_NORMAL = 0x01, // try to stretch to requested size
NS_STRETCH_NEARER = 0x02, // stretch very close to requested size
NS_STRETCH_SMALLER = 0x04, // don't stretch more than requested size
NS_STRETCH_LARGER = 0x08, // don't stretch less than requested size
// A largeop in displaystyle
NS_STRETCH_LARGEOP = 0x10,
NS_STRETCH_INTEGRAL = 0x20,
// Intended for internal use:
// Find the widest metrics that might be returned from a vertical stretch
NS_STRETCH_MAXWIDTH = 0x40
};
// A single glyph in our internal representation is characterized by a 'code@font'
// pair. The 'code' is interpreted as a Unicode point or as the direct glyph index
// (depending on the type of nsGlyphTable where this comes from). The 'font' is a
// numeric identifier given to the font to which the glyph belongs.
struct nsGlyphCode {
PRUnichar code[2];
PRInt32 font;
PRInt32 Length() { return (code[1] == PRUnichar('\0') ? 1 : 2); }
PRBool Exists() const
{
return (code[0] != 0);
}
PRBool operator==(const nsGlyphCode& other) const
{
return (other.code[0] == code[0] && other.code[1] == code[1] &&
other.font == font);
}
PRBool operator!=(const nsGlyphCode& other) const
{
return ! operator==(other);
}
};
// Class used to handle stretchy symbols (accent, delimiter and boundary symbols).
// There are composite characters that need to be built recursively from other
// characters. Since these are rare we use a light-weight mechanism to handle
// them. Specifically, as need arises we append a singly-linked list of child
// chars with their mParent pointing to the first element in the list, except in
// the originating first element itself where it points to null. mSibling points
// to the next element in the list. Since the originating first element is the
// parent of the others, we call it the "root" char of the list. Testing !mParent
// tells whether you are that "root" during the recursion. The parent delegates
// most of the tasks to the children.
class nsMathMLChar
{
public:
// constructor and destructor
nsMathMLChar(nsMathMLChar* aParent = nsnull) {
MOZ_COUNT_CTOR(nsMathMLChar);
mStyleContext = nsnull;
mSibling = nsnull;
mParent = aParent;
mUnscaledAscent = 0;
mScaleX = mScaleY = 1.0;
mDrawNormal = PR_TRUE;
}
~nsMathMLChar() { // not a virtual destructor: this class is not intended to be subclassed
MOZ_COUNT_DTOR(nsMathMLChar);
// there is only one style context owned by the "root" char
// and it may be used by child chars as well
if (!mParent && mStyleContext) { // only the "root" need to release it
mStyleContext->Release();
}
if (mSibling) {
delete mSibling;
}
}
nsresult
Display(nsDisplayListBuilder* aBuilder,
nsIFrame* aForFrame,
const nsDisplayListSet& aLists,
const nsRect* aSelectedRect = nsnull);
void PaintForeground(nsPresContext* aPresContext,
nsRenderingContext& aRenderingContext,
nsPoint aPt,
PRBool aIsSelected);
// This is the method called to ask the char to stretch itself.
// @param aContainerSize - IN - suggested size for the stretched char
// @param aDesiredStretchSize - OUT - the size that the char wants
nsresult
Stretch(nsPresContext* aPresContext,
nsRenderingContext& aRenderingContext,
nsStretchDirection aStretchDirection,
const nsBoundingMetrics& aContainerSize,
nsBoundingMetrics& aDesiredStretchSize,
PRUint32 aStretchHint = NS_STRETCH_NORMAL);
void
SetData(nsPresContext* aPresContext,
nsString& aData);
void
GetData(nsString& aData) {
aData = mData;
}
PRInt32
Length() {
return mData.Length();
}
nsStretchDirection
GetStretchDirection() {
return mDirection;
}
// Sometimes we only want to pass the data to another routine,
// this function helps to avoid copying
const PRUnichar*
get() {
return mData.get();
}
void
GetRect(nsRect& aRect) {
aRect = mRect;
}
void
SetRect(const nsRect& aRect) {
mRect = aRect;
// shift the orgins of child chars if any
if (!mParent && mSibling) { // only a "root" having child chars can enter here
for (nsMathMLChar* child = mSibling; child; child = child->mSibling) {
nsRect rect;
child->GetRect(rect);
rect.MoveBy(mRect.x, mRect.y);
child->SetRect(rect);
}
}
}
// Get the maximum width that the character might have after a vertical
// Stretch().
//
// @param aStretchHint can be the value that will be passed to Stretch().
// It is used to determine whether the operator is stretchy or a largeop.
// @param aMaxSize is the value of the "maxsize" attribute.
// @param aMaxSizeIsAbsolute indicates whether the aMaxSize is an absolute
// value in app units (PR_TRUE) or a multiplier of the base size (PR_FALSE).
nscoord
GetMaxWidth(nsPresContext* aPresContext,
nsRenderingContext& aRenderingContext,
PRUint32 aStretchHint = NS_STRETCH_NORMAL,
float aMaxSize = NS_MATHML_OPERATOR_SIZE_INFINITY,
// Perhaps just nsOperatorFlags aFlags.
// But need DisplayStyle for largeOp,
// or remove the largeop bit from flags.
PRBool aMaxSizeIsAbsolute = PR_FALSE);
// Metrics that _exactly_ enclose the char. The char *must* have *already*
// being stretched before you can call the GetBoundingMetrics() method.
// IMPORTANT: since chars have their own style contexts, and may be rendered
// with glyphs that are not in the parent font, just calling the default
// aRenderingContext.GetBoundingMetrics(aChar) can give incorrect results.
void
GetBoundingMetrics(nsBoundingMetrics& aBoundingMetrics) {
aBoundingMetrics = mBoundingMetrics;
}
void
SetBoundingMetrics(nsBoundingMetrics& aBoundingMetrics) {
mBoundingMetrics = aBoundingMetrics;
}
// Hooks to access the extra leaf style contexts given to the MathMLChars.
// They provide an interface to make them accessible to the Style System via
// the Get/Set AdditionalStyleContext() APIs. Owners of MathMLChars
// should honor these APIs.
nsStyleContext* GetStyleContext() const;
void SetStyleContext(nsStyleContext* aStyleContext);
protected:
friend class nsGlyphTable;
nsString mData;
// support for handling composite stretchy chars like TeX over/under braces
nsMathMLChar* mSibling;
nsMathMLChar* mParent;
private:
nsRect mRect;
nsStretchDirection mDirection;
nsBoundingMetrics mBoundingMetrics;
nsStyleContext* mStyleContext;
nsGlyphTable* mGlyphTable;
nsGlyphCode mGlyph;
// mFamily is non-empty when the family for the current size is different
// from the family in the nsStyleContext.
nsString mFamily;
// mUnscaledAscent is the actual ascent of the char.
nscoord mUnscaledAscent;
// mScaleX, mScaleY are the factors by which we scale the char.
float mScaleX, mScaleY;
// mDrawNormal indicates whether we use special glyphs or not.
PRPackedBool mDrawNormal;
class StretchEnumContext;
friend class StretchEnumContext;
// helper methods
nsresult
StretchInternal(nsPresContext* aPresContext,
nsRenderingContext& aRenderingContext,
nsStretchDirection& aStretchDirection,
const nsBoundingMetrics& aContainerSize,
nsBoundingMetrics& aDesiredStretchSize,
PRUint32 aStretchHint,
float aMaxSize = NS_MATHML_OPERATOR_SIZE_INFINITY,
PRBool aMaxSizeIsAbsolute = PR_FALSE);
nsresult
ComposeChildren(nsPresContext* aPresContext,
nsRenderingContext& aRenderingContext,
nsGlyphTable* aGlyphTable,
nscoord aTargetSize,
nsBoundingMetrics& aCompositeSize,
PRUint32 aStretchHint);
nsresult
PaintVertically(nsPresContext* aPresContext,
nsRenderingContext& aRenderingContext,
nsFont& aFont,
nsStyleContext* aStyleContext,
nsGlyphTable* aGlyphTable,
nsRect& aRect);
nsresult
PaintHorizontally(nsPresContext* aPresContext,
nsRenderingContext& aRenderingContext,
nsFont& aFont,
nsStyleContext* aStyleContext,
nsGlyphTable* aGlyphTable,
nsRect& aRect);
void
ApplyTransforms(nsRenderingContext& aRenderingContext, nsRect &r);
};
#endif /* nsMathMLChar_h___ */
|