2007-06-12 10:10:23 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 15:12:37 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
1999-09-21 06:12:01 +04:00
|
|
|
|
2013-08-31 01:37:12 +04:00
|
|
|
#include "nsMathMLChar.h"
|
2014-10-19 16:22:22 +04:00
|
|
|
|
2014-10-24 19:28:14 +04:00
|
|
|
#include "gfxTextRun.h"
|
2014-10-19 16:22:22 +04:00
|
|
|
#include "gfxUtils.h"
|
|
|
|
#include "mozilla/gfx/2D.h"
|
2013-02-16 07:55:36 +04:00
|
|
|
#include "mozilla/MathAlgorithms.h"
|
2016-08-23 07:09:32 +03:00
|
|
|
#include "mozilla/Unused.h"
|
2013-02-16 07:55:36 +04:00
|
|
|
|
2016-06-07 23:10:18 +03:00
|
|
|
#include "nsAutoPtr.h"
|
1999-09-21 06:12:01 +04:00
|
|
|
#include "nsCOMPtr.h"
|
2014-10-20 13:55:49 +04:00
|
|
|
#include "nsDeviceContext.h"
|
2014-10-24 19:28:14 +04:00
|
|
|
#include "nsFontMetrics.h"
|
2013-08-31 01:37:12 +04:00
|
|
|
#include "nsIFrame.h"
|
2014-10-19 16:22:22 +04:00
|
|
|
#include "nsLayoutUtils.h"
|
2004-08-01 03:15:21 +04:00
|
|
|
#include "nsPresContext.h"
|
2003-02-22 03:32:13 +03:00
|
|
|
#include "nsStyleContext.h"
|
2002-02-20 01:49:12 +03:00
|
|
|
#include "nsUnicharUtils.h"
|
2011-04-08 05:04:40 +04:00
|
|
|
#include "nsRenderingContext.h"
|
1999-09-21 06:12:01 +04:00
|
|
|
|
2011-06-12 06:30:16 +04:00
|
|
|
#include "mozilla/Preferences.h"
|
2001-02-02 12:40:53 +03:00
|
|
|
#include "nsIPersistentProperties2.h"
|
|
|
|
#include "nsIObserverService.h"
|
|
|
|
#include "nsIObserver.h"
|
|
|
|
#include "nsNetUtil.h"
|
2014-09-21 20:41:03 +04:00
|
|
|
#include "nsContentUtils.h"
|
2001-02-02 12:40:53 +03:00
|
|
|
|
2011-09-09 06:27:13 +04:00
|
|
|
#include "mozilla/LookAndFeel.h"
|
2000-03-28 13:38:24 +04:00
|
|
|
#include "nsCSSRendering.h"
|
2016-08-15 09:43:21 +03:00
|
|
|
#include "mozilla/Sprintf.h"
|
2000-03-28 13:38:24 +04:00
|
|
|
|
2006-01-26 05:29:17 +03:00
|
|
|
#include "nsDisplayList.h"
|
2002-01-11 05:57:03 +03:00
|
|
|
|
1999-09-21 06:12:01 +04:00
|
|
|
#include "nsMathMLOperators.h"
|
2013-01-15 16:22:03 +04:00
|
|
|
#include <algorithm>
|
1999-09-21 06:12:01 +04:00
|
|
|
|
2014-04-23 17:57:42 +04:00
|
|
|
#include "gfxMathTable.h"
|
2014-11-11 10:37:00 +03:00
|
|
|
#include "nsUnicodeScriptCodes.h"
|
2014-04-23 17:57:42 +04:00
|
|
|
|
2011-06-12 06:30:16 +04:00
|
|
|
using namespace mozilla;
|
2014-10-19 16:22:22 +04:00
|
|
|
using namespace mozilla::gfx;
|
2015-02-10 10:27:40 +03:00
|
|
|
using namespace mozilla::image;
|
2011-06-12 06:30:16 +04:00
|
|
|
|
2001-02-02 12:40:53 +03:00
|
|
|
//#define NOISY_SEARCH 1
|
2000-03-28 13:38:24 +04:00
|
|
|
|
2014-05-12 03:32:00 +04:00
|
|
|
// BUG 848725 Drawing failure with stretchy horizontal parenthesis when no fonts
|
|
|
|
// are installed. "kMaxScaleFactor" is required to limit the scale for the
|
|
|
|
// vertical and horizontal stretchy operators.
|
|
|
|
static const float kMaxScaleFactor = 20.0;
|
2014-04-23 17:57:42 +04:00
|
|
|
static const float kLargeOpFactor = float(M_SQRT2);
|
|
|
|
static const float kIntegralFactor = 2.0;
|
|
|
|
|
2014-06-06 10:09:23 +04:00
|
|
|
static void
|
2014-10-25 10:30:00 +04:00
|
|
|
NormalizeDefaultFont(nsFont& aFont, float aFontSizeInflation)
|
2014-06-06 10:09:23 +04:00
|
|
|
{
|
|
|
|
if (aFont.fontlist.GetDefaultFontType() != eFamily_none) {
|
2014-08-06 01:58:40 +04:00
|
|
|
aFont.fontlist.Append(FontFamilyName(aFont.fontlist.GetDefaultFontType()));
|
2014-06-06 10:09:23 +04:00
|
|
|
aFont.fontlist.SetDefaultFontType(eFamily_none);
|
|
|
|
}
|
2014-10-25 10:30:00 +04:00
|
|
|
aFont.size = NSToCoordRound(aFont.size * aFontSizeInflation);
|
2014-06-06 10:09:23 +04:00
|
|
|
}
|
|
|
|
|
2012-08-10 19:29:59 +04:00
|
|
|
// -----------------------------------------------------------------------------
|
2014-02-13 18:53:52 +04:00
|
|
|
static const nsGlyphCode kNullGlyph = {{{0, 0}}, 0};
|
2000-03-28 13:38:24 +04:00
|
|
|
|
2012-08-10 19:29:59 +04:00
|
|
|
// -----------------------------------------------------------------------------
|
2000-03-28 13:38:24 +04:00
|
|
|
// nsGlyphTable is a class that provides an interface for accessing glyphs
|
|
|
|
// of stretchy chars. It acts like a table that stores the variants of bigger
|
|
|
|
// sizes (if any) and the partial glyphs needed to build extensible symbols.
|
1999-09-21 06:12:01 +04:00
|
|
|
//
|
2014-04-23 17:57:42 +04:00
|
|
|
// Bigger sizes (if any) of the char can then be retrieved with BigOf(...).
|
|
|
|
// Partial glyphs can be retrieved with ElementAt(...).
|
2001-02-02 12:40:53 +03:00
|
|
|
//
|
2000-03-28 13:38:24 +04:00
|
|
|
// A table consists of "nsGlyphCode"s which are viewed either as Unicode
|
2014-04-23 17:57:42 +04:00
|
|
|
// points (for nsPropertiesTable) or as direct glyph indices (for
|
|
|
|
// nsOpenTypeTable)
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
class nsGlyphTable {
|
|
|
|
public:
|
|
|
|
virtual ~nsGlyphTable() {}
|
|
|
|
|
2014-06-06 10:09:23 +04:00
|
|
|
virtual const FontFamilyName&
|
2014-04-23 17:57:42 +04:00
|
|
|
FontNameFor(const nsGlyphCode& aGlyphCode) const = 0;
|
|
|
|
|
|
|
|
// Getters for the parts
|
2015-12-16 00:56:41 +03:00
|
|
|
virtual nsGlyphCode ElementAt(DrawTarget* aDrawTarget,
|
2014-04-23 17:57:42 +04:00
|
|
|
int32_t aAppUnitsPerDevPixel,
|
|
|
|
gfxFontGroup* aFontGroup,
|
|
|
|
char16_t aChar,
|
|
|
|
bool aVertical,
|
|
|
|
uint32_t aPosition) = 0;
|
2015-12-16 00:56:41 +03:00
|
|
|
virtual nsGlyphCode BigOf(DrawTarget* aDrawTarget,
|
2014-04-23 17:57:42 +04:00
|
|
|
int32_t aAppUnitsPerDevPixel,
|
|
|
|
gfxFontGroup* aFontGroup,
|
|
|
|
char16_t aChar,
|
|
|
|
bool aVertical,
|
|
|
|
uint32_t aSize) = 0;
|
|
|
|
|
|
|
|
// True if this table contains parts to render this char
|
2015-12-16 00:56:41 +03:00
|
|
|
virtual bool HasPartsOf(DrawTarget* aDrawTarget,
|
2014-04-23 17:57:42 +04:00
|
|
|
int32_t aAppUnitsPerDevPixel,
|
|
|
|
gfxFontGroup* aFontGroup,
|
|
|
|
char16_t aChar,
|
|
|
|
bool aVertical) = 0;
|
|
|
|
|
2016-08-19 15:14:22 +03:00
|
|
|
virtual already_AddRefed<gfxTextRun>
|
2016-04-19 19:13:28 +03:00
|
|
|
MakeTextRun(DrawTarget* aDrawTarget,
|
|
|
|
int32_t aAppUnitsPerDevPixel,
|
|
|
|
gfxFontGroup* aFontGroup,
|
|
|
|
const nsGlyphCode& aGlyph) = 0;
|
2014-04-23 17:57:42 +04:00
|
|
|
protected:
|
|
|
|
nsGlyphTable() : mCharCache(0) {}
|
|
|
|
// For speedy re-use, we always cache the last data used in the table.
|
|
|
|
// mCharCache is the Unicode point of the last char that was queried in this
|
|
|
|
// table.
|
|
|
|
char16_t mCharCache;
|
|
|
|
};
|
|
|
|
|
|
|
|
// An instance of nsPropertiesTable is associated with one primary font. Extra
|
|
|
|
// glyphs can be taken in other additional fonts when stretching certain
|
|
|
|
// characters.
|
|
|
|
// These supplementary fonts are referred to as "external" fonts to the table.
|
2000-03-28 13:38:24 +04:00
|
|
|
|
2012-08-10 19:29:59 +04:00
|
|
|
// General format of MathFont Property Files from which glyph data are
|
|
|
|
// retrieved:
|
|
|
|
// -----------------------------------------------------------------------------
|
2001-02-02 12:40:53 +03:00
|
|
|
// Each font should have its set of glyph data. For example, the glyph data for
|
|
|
|
// the "Symbol" font and the "MT Extra" font are in "mathfontSymbol.properties"
|
2012-08-10 19:29:59 +04:00
|
|
|
// and "mathfontMTExtra.properties", respectively. The mathfont property file
|
|
|
|
// is a set of all the stretchy MathML characters that can be rendered with that
|
|
|
|
// font using larger and/or partial glyphs. The entry of each stretchy character
|
|
|
|
// in the mathfont property file gives, in that order, the 4 partial glyphs:
|
|
|
|
// Top (or Left), Middle, Bottom (or Right), Glue; and the variants of bigger
|
|
|
|
// sizes (if any).
|
2001-02-02 12:40:53 +03:00
|
|
|
// A position that is not relevant to a particular character is indicated there
|
|
|
|
// with the UNICODE REPLACEMENT CHARACTER 0xFFFD.
|
2012-08-10 19:29:59 +04:00
|
|
|
// -----------------------------------------------------------------------------
|
2000-03-28 13:38:24 +04:00
|
|
|
|
2001-02-02 12:40:53 +03:00
|
|
|
#define NS_TABLE_STATE_ERROR -1
|
|
|
|
#define NS_TABLE_STATE_EMPTY 0
|
|
|
|
#define NS_TABLE_STATE_READY 1
|
|
|
|
|
2001-03-23 12:46:24 +03:00
|
|
|
// helper to trim off comments from data in a MathFont Property File
|
|
|
|
static void
|
|
|
|
Clean(nsString& aValue)
|
|
|
|
{
|
|
|
|
// chop the trailing # comment portion if any ...
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t comment = aValue.RFindChar('#');
|
2001-03-23 12:46:24 +03:00
|
|
|
if (comment > 0) aValue.Truncate(comment);
|
|
|
|
aValue.CompressWhitespace();
|
|
|
|
}
|
|
|
|
|
|
|
|
// helper to load a MathFont Property File
|
|
|
|
static nsresult
|
|
|
|
LoadProperties(const nsString& aName,
|
|
|
|
nsCOMPtr<nsIPersistentProperties>& aProperties)
|
|
|
|
{
|
|
|
|
nsAutoString uriStr;
|
2004-06-17 04:13:25 +04:00
|
|
|
uriStr.AssignLiteral("resource://gre/res/fonts/mathfont");
|
2001-03-23 12:46:24 +03:00
|
|
|
uriStr.Append(aName);
|
|
|
|
uriStr.StripWhitespace(); // that may come from aName
|
2004-06-17 04:13:25 +04:00
|
|
|
uriStr.AppendLiteral(".properties");
|
2014-09-21 20:41:03 +04:00
|
|
|
return NS_LoadPersistentPropertiesFromURISpec(getter_AddRefs(aProperties),
|
2015-11-09 05:54:38 +03:00
|
|
|
NS_ConvertUTF16toUTF8(uriStr));
|
2001-03-23 12:46:24 +03:00
|
|
|
}
|
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
class nsPropertiesTable final : public nsGlyphTable {
|
2000-03-28 13:38:24 +04:00
|
|
|
public:
|
2014-04-23 17:57:42 +04:00
|
|
|
explicit nsPropertiesTable(const nsString& aPrimaryFontName)
|
2014-06-06 10:09:23 +04:00
|
|
|
: mState(NS_TABLE_STATE_EMPTY)
|
2001-03-23 12:46:24 +03:00
|
|
|
{
|
2014-04-23 17:57:42 +04:00
|
|
|
MOZ_COUNT_CTOR(nsPropertiesTable);
|
2014-06-06 10:09:23 +04:00
|
|
|
mGlyphCodeFonts.AppendElement(FontFamilyName(aPrimaryFontName, eUnquotedName));
|
2000-03-28 13:38:24 +04:00
|
|
|
}
|
|
|
|
|
2014-04-23 17:57:42 +04:00
|
|
|
~nsPropertiesTable()
|
2000-03-28 13:38:24 +04:00
|
|
|
{
|
2014-04-23 17:57:42 +04:00
|
|
|
MOZ_COUNT_DTOR(nsPropertiesTable);
|
2000-03-28 13:38:24 +04:00
|
|
|
}
|
|
|
|
|
2014-06-06 10:09:23 +04:00
|
|
|
const FontFamilyName& PrimaryFontName() const
|
2007-12-05 06:58:09 +03:00
|
|
|
{
|
2014-06-06 10:09:23 +04:00
|
|
|
return mGlyphCodeFonts[0];
|
2007-12-05 06:58:09 +03:00
|
|
|
}
|
|
|
|
|
2014-06-06 10:09:23 +04:00
|
|
|
const FontFamilyName&
|
2015-03-21 19:28:04 +03:00
|
|
|
FontNameFor(const nsGlyphCode& aGlyphCode) const override
|
2007-12-05 06:58:09 +03:00
|
|
|
{
|
2014-02-13 18:53:52 +04:00
|
|
|
NS_ASSERTION(!aGlyphCode.IsGlyphID(),
|
2014-04-23 17:57:42 +04:00
|
|
|
"nsPropertiesTable can only access glyphs by code point");
|
2014-06-06 10:09:23 +04:00
|
|
|
return mGlyphCodeFonts[aGlyphCode.font];
|
2000-03-28 13:38:24 +04:00
|
|
|
}
|
|
|
|
|
2015-12-16 00:56:41 +03:00
|
|
|
virtual nsGlyphCode ElementAt(DrawTarget* aDrawTarget,
|
2014-04-23 17:57:42 +04:00
|
|
|
int32_t aAppUnitsPerDevPixel,
|
|
|
|
gfxFontGroup* aFontGroup,
|
|
|
|
char16_t aChar,
|
|
|
|
bool aVertical,
|
2015-03-21 19:28:04 +03:00
|
|
|
uint32_t aPosition) override;
|
2014-04-23 17:57:42 +04:00
|
|
|
|
2015-12-16 00:56:41 +03:00
|
|
|
virtual nsGlyphCode BigOf(DrawTarget* aDrawTarget,
|
2014-04-23 17:57:42 +04:00
|
|
|
int32_t aAppUnitsPerDevPixel,
|
|
|
|
gfxFontGroup* aFontGroup,
|
|
|
|
char16_t aChar,
|
|
|
|
bool aVertical,
|
2015-03-21 19:28:04 +03:00
|
|
|
uint32_t aSize) override
|
2014-04-23 17:57:42 +04:00
|
|
|
{
|
2015-12-16 00:56:41 +03:00
|
|
|
return ElementAt(aDrawTarget, aAppUnitsPerDevPixel, aFontGroup,
|
2014-04-23 17:57:42 +04:00
|
|
|
aChar, aVertical, 4 + aSize);
|
2000-03-28 13:38:24 +04:00
|
|
|
}
|
2014-02-13 18:53:52 +04:00
|
|
|
|
2015-12-16 00:56:41 +03:00
|
|
|
virtual bool HasPartsOf(DrawTarget* aDrawTarget,
|
2014-04-23 17:57:42 +04:00
|
|
|
int32_t aAppUnitsPerDevPixel,
|
|
|
|
gfxFontGroup* aFontGroup,
|
|
|
|
char16_t aChar,
|
2015-03-21 19:28:04 +03:00
|
|
|
bool aVertical) override
|
2014-04-23 17:57:42 +04:00
|
|
|
{
|
2015-12-16 00:56:41 +03:00
|
|
|
return (ElementAt(aDrawTarget, aAppUnitsPerDevPixel, aFontGroup,
|
2014-04-23 17:57:42 +04:00
|
|
|
aChar, aVertical, 0).Exists() ||
|
2015-12-16 00:56:41 +03:00
|
|
|
ElementAt(aDrawTarget, aAppUnitsPerDevPixel, aFontGroup,
|
2014-04-23 17:57:42 +04:00
|
|
|
aChar, aVertical, 1).Exists() ||
|
2015-12-16 00:56:41 +03:00
|
|
|
ElementAt(aDrawTarget, aAppUnitsPerDevPixel, aFontGroup,
|
2014-04-23 17:57:42 +04:00
|
|
|
aChar, aVertical, 2).Exists() ||
|
2015-12-16 00:56:41 +03:00
|
|
|
ElementAt(aDrawTarget, aAppUnitsPerDevPixel, aFontGroup,
|
2014-04-23 17:57:42 +04:00
|
|
|
aChar, aVertical, 3).Exists());
|
2000-03-28 13:38:24 +04:00
|
|
|
}
|
|
|
|
|
2016-08-19 15:14:22 +03:00
|
|
|
virtual already_AddRefed<gfxTextRun>
|
2016-04-19 19:13:28 +03:00
|
|
|
MakeTextRun(DrawTarget* aDrawTarget,
|
|
|
|
int32_t aAppUnitsPerDevPixel,
|
|
|
|
gfxFontGroup* aFontGroup,
|
|
|
|
const nsGlyphCode& aGlyph) override;
|
2000-03-28 13:38:24 +04:00
|
|
|
private:
|
|
|
|
|
2014-06-06 10:09:23 +04:00
|
|
|
// mGlyphCodeFonts[0] is the primary font associated to this table. The
|
|
|
|
// others are possible "external" fonts for glyphs not in the primary font
|
2001-03-23 12:46:24 +03:00
|
|
|
// but which are needed to stretch certain characters in the table
|
2014-06-06 10:09:23 +04:00
|
|
|
nsTArray<FontFamilyName> mGlyphCodeFonts;
|
2012-10-10 09:00:05 +04:00
|
|
|
|
2001-03-23 12:46:24 +03:00
|
|
|
// Tri-state variable for error/empty/ready
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t mState;
|
2001-03-23 12:46:24 +03:00
|
|
|
|
2012-08-10 19:29:59 +04:00
|
|
|
// The set of glyph data in this table, as provided by the MathFont Property
|
|
|
|
// File
|
2001-03-23 12:46:24 +03:00
|
|
|
nsCOMPtr<nsIPersistentProperties> mGlyphProperties;
|
|
|
|
|
2014-04-23 17:57:42 +04:00
|
|
|
// mGlyphCache is a buffer containing the glyph data associated with
|
|
|
|
// mCharCache.
|
|
|
|
// For a property line 'key = value' in the MathFont Property File,
|
2012-08-10 19:29:59 +04:00
|
|
|
// mCharCache will retain the 'key' -- which is a Unicode point, while
|
|
|
|
// mGlyphCache will retain the 'value', which is a consecutive list of
|
|
|
|
// nsGlyphCodes, i.e., the pairs of 'code@font' needed by the char -- in
|
|
|
|
// which 'code@0' can be specified
|
|
|
|
// without the optional '@0'. However, to ease subsequent processing,
|
|
|
|
// mGlyphCache excludes the '@' symbol and explicitly inserts all optional '0'
|
|
|
|
// that indicates the primary font identifier. Specifically therefore, the
|
|
|
|
// k-th glyph is characterized by :
|
2012-10-10 09:00:05 +04:00
|
|
|
// 1) mGlyphCache[3*k],mGlyphCache[3*k+1] : its Unicode point
|
2012-08-10 19:29:59 +04:00
|
|
|
// 2) mGlyphCache[3*k+2] : the numeric identifier of the font where it comes
|
|
|
|
// from.
|
2001-03-23 12:46:24 +03:00
|
|
|
// A font identifier of '0' means the default primary font associated to this
|
2012-08-10 19:29:59 +04:00
|
|
|
// table. Other digits map to the "external" fonts that may have been
|
|
|
|
// specified in the MathFont Property File.
|
2001-03-23 12:46:24 +03:00
|
|
|
nsString mGlyphCache;
|
2001-02-02 12:40:53 +03:00
|
|
|
};
|
2000-03-28 13:38:24 +04:00
|
|
|
|
2014-04-23 17:57:42 +04:00
|
|
|
/* virtual */
|
2001-02-02 12:40:53 +03:00
|
|
|
nsGlyphCode
|
2015-12-16 00:56:41 +03:00
|
|
|
nsPropertiesTable::ElementAt(DrawTarget* /* aDrawTarget */,
|
2014-04-23 17:57:42 +04:00
|
|
|
int32_t /* aAppUnitsPerDevPixel */,
|
|
|
|
gfxFontGroup* /* aFontGroup */,
|
|
|
|
char16_t aChar,
|
|
|
|
bool /* aVertical */,
|
|
|
|
uint32_t aPosition)
|
2001-02-02 12:40:53 +03:00
|
|
|
{
|
2001-03-23 12:46:24 +03:00
|
|
|
if (mState == NS_TABLE_STATE_ERROR) return kNullGlyph;
|
2001-02-02 12:40:53 +03:00
|
|
|
// Load glyph properties if this is the first time we have been here
|
|
|
|
if (mState == NS_TABLE_STATE_EMPTY) {
|
2014-06-06 10:09:23 +04:00
|
|
|
nsAutoString primaryFontName;
|
|
|
|
mGlyphCodeFonts[0].AppendToString(primaryFontName);
|
|
|
|
nsresult rv = LoadProperties(primaryFontName, mGlyphProperties);
|
2012-06-25 23:59:42 +04:00
|
|
|
#ifdef DEBUG
|
2012-09-02 06:35:17 +04:00
|
|
|
nsAutoCString uriStr;
|
2004-06-17 04:13:25 +04:00
|
|
|
uriStr.AssignLiteral("resource://gre/res/fonts/mathfont");
|
2014-06-06 10:09:23 +04:00
|
|
|
LossyAppendUTF16toASCII(primaryFontName, uriStr);
|
|
|
|
uriStr.StripWhitespace(); // that may come from mGlyphCodeFonts
|
2004-06-17 04:13:25 +04:00
|
|
|
uriStr.AppendLiteral(".properties");
|
2001-10-16 07:53:44 +04:00
|
|
|
printf("Loading %s ... %s\n",
|
|
|
|
uriStr.get(),
|
|
|
|
(NS_FAILED(rv)) ? "Failed" : "Done");
|
2001-02-02 12:40:53 +03:00
|
|
|
#endif
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
mState = NS_TABLE_STATE_ERROR; // never waste time with this table again
|
2001-03-23 12:46:24 +03:00
|
|
|
return kNullGlyph;
|
2001-02-02 12:40:53 +03:00
|
|
|
}
|
|
|
|
mState = NS_TABLE_STATE_READY;
|
2001-03-23 12:46:24 +03:00
|
|
|
|
|
|
|
// see if there are external fonts needed for certain chars in this table
|
2012-09-02 06:35:17 +04:00
|
|
|
nsAutoCString key;
|
2002-08-30 21:13:34 +04:00
|
|
|
nsAutoString value;
|
2012-08-22 19:56:38 +04:00
|
|
|
for (int32_t i = 1; ; i++) {
|
2004-06-17 04:13:25 +04:00
|
|
|
key.AssignLiteral("external.");
|
2001-03-23 12:46:24 +03:00
|
|
|
key.AppendInt(i, 10);
|
2001-03-30 06:39:38 +04:00
|
|
|
rv = mGlyphProperties->GetStringProperty(key, value);
|
2001-03-23 12:46:24 +03:00
|
|
|
if (NS_FAILED(rv)) break;
|
|
|
|
Clean(value);
|
2014-06-06 10:09:23 +04:00
|
|
|
mGlyphCodeFonts.AppendElement(FontFamilyName(value, eUnquotedName)); // i.e., mGlyphCodeFonts[i] holds this font name
|
2001-03-23 12:46:24 +03:00
|
|
|
}
|
2000-03-28 13:38:24 +04:00
|
|
|
}
|
|
|
|
|
2001-02-02 12:40:53 +03:00
|
|
|
// Update our cache if it is not associated to this character
|
2014-02-13 18:53:52 +04:00
|
|
|
if (mCharCache != aChar) {
|
2002-08-30 21:13:34 +04:00
|
|
|
// The key in the property file is interpreted as ASCII and kept
|
|
|
|
// as such ...
|
2016-08-15 09:44:00 +03:00
|
|
|
char key[10]; SprintfLiteral(key, "\\u%04X", aChar);
|
2002-08-30 21:13:34 +04:00
|
|
|
nsAutoString value;
|
2012-08-10 19:29:59 +04:00
|
|
|
nsresult rv = mGlyphProperties->GetStringProperty(nsDependentCString(key),
|
|
|
|
value);
|
2001-03-23 12:46:24 +03:00
|
|
|
if (NS_FAILED(rv)) return kNullGlyph;
|
|
|
|
Clean(value);
|
2012-08-10 19:29:59 +04:00
|
|
|
// See if this char uses external fonts; e.g., if the 2nd glyph is taken
|
|
|
|
// from the external font '1', the property line looks like
|
|
|
|
// \uNNNN = \uNNNN\uNNNN@1\uNNNN.
|
|
|
|
// This is where mGlyphCache is pre-processed to explicitly store all glyph
|
|
|
|
// codes as combined pairs of 'code@font', excluding the '@' separator. This
|
|
|
|
// means that mGlyphCache[3*k],mGlyphCache[3*k+1] will later be rendered
|
2014-06-06 10:09:23 +04:00
|
|
|
// with mGlyphCodeFonts[mGlyphCache[3*k+2]]
|
2012-08-10 19:29:59 +04:00
|
|
|
// Note: font identifier is internally an ASCII digit to avoid the null
|
|
|
|
// char issue
|
2007-12-05 06:58:09 +03:00
|
|
|
nsAutoString buffer;
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t length = value.Length();
|
|
|
|
int32_t i = 0; // index in value
|
2007-12-05 06:58:09 +03:00
|
|
|
while (i < length) {
|
2014-01-04 19:02:17 +04:00
|
|
|
char16_t code = value[i];
|
2007-12-05 06:58:09 +03:00
|
|
|
++i;
|
2011-06-22 19:49:11 +04:00
|
|
|
buffer.Append(code);
|
|
|
|
// Read the next word if we have a non-BMP character.
|
|
|
|
if (i < length && NS_IS_HIGH_SURROGATE(code)) {
|
|
|
|
code = value[i];
|
|
|
|
++i;
|
|
|
|
} else {
|
2014-01-04 19:02:17 +04:00
|
|
|
code = char16_t('\0');
|
2011-06-22 19:49:11 +04:00
|
|
|
}
|
|
|
|
buffer.Append(code);
|
|
|
|
|
2007-12-05 06:58:09 +03:00
|
|
|
// See if an external font is needed for the code point.
|
|
|
|
// Limit of 9 external fonts
|
2014-01-04 19:02:17 +04:00
|
|
|
char16_t font = 0;
|
|
|
|
if (i+1 < length && value[i] == char16_t('@') &&
|
|
|
|
value[i+1] >= char16_t('0') && value[i+1] <= char16_t('9')) {
|
2007-12-05 06:58:09 +03:00
|
|
|
++i;
|
|
|
|
font = value[i] - '0';
|
|
|
|
++i;
|
2014-06-06 10:09:23 +04:00
|
|
|
if (font >= mGlyphCodeFonts.Length()) {
|
2010-05-13 16:19:50 +04:00
|
|
|
NS_ERROR("Nonexistent font referenced in glyph table");
|
2007-12-05 06:58:09 +03:00
|
|
|
return kNullGlyph;
|
|
|
|
}
|
2001-03-23 12:46:24 +03:00
|
|
|
// The char cannot be handled if this font is not installed
|
2014-06-06 10:09:23 +04:00
|
|
|
if (!mGlyphCodeFonts[font].mName.Length()) {
|
2001-04-28 11:39:20 +04:00
|
|
|
return kNullGlyph;
|
|
|
|
}
|
2001-03-23 12:46:24 +03:00
|
|
|
}
|
|
|
|
buffer.Append(font);
|
|
|
|
}
|
|
|
|
// update our cache with the new settings
|
|
|
|
mGlyphCache.Assign(buffer);
|
2014-02-13 18:53:52 +04:00
|
|
|
mCharCache = aChar;
|
2001-02-02 12:40:53 +03:00
|
|
|
}
|
2000-03-28 13:38:24 +04:00
|
|
|
|
2012-08-10 19:29:59 +04:00
|
|
|
// 3* is to account for the code@font pairs
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t index = 3*aPosition;
|
2012-08-21 04:14:20 +04:00
|
|
|
if (index+2 >= mGlyphCache.Length()) return kNullGlyph;
|
2001-03-23 12:46:24 +03:00
|
|
|
nsGlyphCode ch;
|
2011-06-22 19:49:11 +04:00
|
|
|
ch.code[0] = mGlyphCache.CharAt(index);
|
|
|
|
ch.code[1] = mGlyphCache.CharAt(index + 1);
|
|
|
|
ch.font = mGlyphCache.CharAt(index + 2);
|
2014-01-04 19:02:17 +04:00
|
|
|
return ch.code[0] == char16_t(0xFFFD) ? kNullGlyph : ch;
|
2001-02-02 12:40:53 +03:00
|
|
|
}
|
|
|
|
|
2014-04-23 17:57:42 +04:00
|
|
|
/* virtual */
|
2016-08-19 15:14:22 +03:00
|
|
|
already_AddRefed<gfxTextRun>
|
2015-12-16 00:56:41 +03:00
|
|
|
nsPropertiesTable::MakeTextRun(DrawTarget* aDrawTarget,
|
2014-04-23 17:57:42 +04:00
|
|
|
int32_t aAppUnitsPerDevPixel,
|
|
|
|
gfxFontGroup* aFontGroup,
|
|
|
|
const nsGlyphCode& aGlyph)
|
2001-02-02 12:40:53 +03:00
|
|
|
{
|
2014-04-23 17:57:42 +04:00
|
|
|
NS_ASSERTION(!aGlyph.IsGlyphID(),
|
|
|
|
"nsPropertiesTable can only access glyphs by code point");
|
2014-02-13 18:53:52 +04:00
|
|
|
return aFontGroup->
|
2015-12-16 00:56:41 +03:00
|
|
|
MakeTextRun(aGlyph.code, aGlyph.Length(), aDrawTarget,
|
2014-12-22 19:35:54 +03:00
|
|
|
aAppUnitsPerDevPixel, 0, nullptr);
|
2001-02-02 12:40:53 +03:00
|
|
|
}
|
|
|
|
|
2014-04-23 17:57:42 +04:00
|
|
|
// An instance of nsOpenTypeTable is associated with one gfxFontEntry that
|
|
|
|
// corresponds to an Open Type font with a MATH table. All the glyphs come from
|
|
|
|
// the same font and the calls to access size variants and parts are directly
|
|
|
|
// forwarded to the gfx code.
|
2015-03-21 19:28:04 +03:00
|
|
|
class nsOpenTypeTable final : public nsGlyphTable {
|
2014-04-23 17:57:42 +04:00
|
|
|
public:
|
|
|
|
~nsOpenTypeTable()
|
|
|
|
{
|
|
|
|
MOZ_COUNT_DTOR(nsOpenTypeTable);
|
|
|
|
}
|
|
|
|
|
2015-12-16 00:56:41 +03:00
|
|
|
virtual nsGlyphCode ElementAt(DrawTarget* aDrawTarget,
|
2014-04-23 17:57:42 +04:00
|
|
|
int32_t aAppUnitsPerDevPixel,
|
|
|
|
gfxFontGroup* aFontGroup,
|
|
|
|
char16_t aChar,
|
|
|
|
bool aVertical,
|
2015-03-21 19:28:04 +03:00
|
|
|
uint32_t aPosition) override;
|
2015-12-16 00:56:41 +03:00
|
|
|
virtual nsGlyphCode BigOf(DrawTarget* aDrawTarget,
|
2014-04-23 17:57:42 +04:00
|
|
|
int32_t aAppUnitsPerDevPixel,
|
|
|
|
gfxFontGroup* aFontGroup,
|
|
|
|
char16_t aChar,
|
|
|
|
bool aVertical,
|
2015-03-21 19:28:04 +03:00
|
|
|
uint32_t aSize) override;
|
2015-12-16 00:56:41 +03:00
|
|
|
virtual bool HasPartsOf(DrawTarget* aDrawTarget,
|
2014-04-23 17:57:42 +04:00
|
|
|
int32_t aAppUnitsPerDevPixel,
|
|
|
|
gfxFontGroup* aFontGroup,
|
|
|
|
char16_t aChar,
|
2015-03-21 19:28:04 +03:00
|
|
|
bool aVertical) override;
|
2014-04-23 17:57:42 +04:00
|
|
|
|
2014-06-06 10:09:23 +04:00
|
|
|
const FontFamilyName&
|
2015-03-21 19:28:04 +03:00
|
|
|
FontNameFor(const nsGlyphCode& aGlyphCode) const override {
|
2014-04-23 17:57:42 +04:00
|
|
|
NS_ASSERTION(aGlyphCode.IsGlyphID(),
|
|
|
|
"nsOpenTypeTable can only access glyphs by id");
|
2014-06-06 10:09:23 +04:00
|
|
|
return mFontFamilyName;
|
2014-04-23 17:57:42 +04:00
|
|
|
}
|
|
|
|
|
2016-08-19 15:14:22 +03:00
|
|
|
virtual already_AddRefed<gfxTextRun>
|
2016-04-19 19:13:28 +03:00
|
|
|
MakeTextRun(DrawTarget* aDrawTarget,
|
|
|
|
int32_t aAppUnitsPerDevPixel,
|
|
|
|
gfxFontGroup* aFontGroup,
|
|
|
|
const nsGlyphCode& aGlyph) override;
|
2014-04-23 17:57:42 +04:00
|
|
|
|
|
|
|
// This returns a new OpenTypeTable instance to give access to OpenType MATH
|
|
|
|
// table or nullptr if the font does not have such table. Ownership is passed
|
|
|
|
// to the caller.
|
|
|
|
static nsOpenTypeTable* Create(gfxFont* aFont)
|
|
|
|
{
|
2014-07-02 07:29:00 +04:00
|
|
|
if (!aFont->GetFontEntry()->TryGetMathTable()) {
|
2014-04-23 17:57:42 +04:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
return new nsOpenTypeTable(aFont->GetFontEntry());
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<gfxFontEntry> mFontEntry;
|
2014-06-06 10:09:23 +04:00
|
|
|
FontFamilyName mFontFamilyName;
|
2014-04-23 17:57:42 +04:00
|
|
|
uint32_t mGlyphID;
|
|
|
|
|
|
|
|
explicit nsOpenTypeTable(gfxFontEntry* aFontEntry)
|
2014-06-06 10:09:23 +04:00
|
|
|
: mFontEntry(aFontEntry),
|
|
|
|
mFontFamilyName(aFontEntry->FamilyName(), eUnquotedName) {
|
2014-04-23 17:57:42 +04:00
|
|
|
MOZ_COUNT_CTOR(nsOpenTypeTable);
|
|
|
|
}
|
|
|
|
|
2015-12-16 00:56:41 +03:00
|
|
|
void UpdateCache(DrawTarget* aDrawTarget,
|
2014-04-23 17:57:42 +04:00
|
|
|
int32_t aAppUnitsPerDevPixel,
|
|
|
|
gfxFontGroup* aFontGroup,
|
|
|
|
char16_t aChar);
|
|
|
|
};
|
|
|
|
|
|
|
|
void
|
2015-12-16 00:56:41 +03:00
|
|
|
nsOpenTypeTable::UpdateCache(DrawTarget* aDrawTarget,
|
2014-04-23 17:57:42 +04:00
|
|
|
int32_t aAppUnitsPerDevPixel,
|
|
|
|
gfxFontGroup* aFontGroup,
|
|
|
|
char16_t aChar)
|
|
|
|
{
|
|
|
|
if (mCharCache != aChar) {
|
2016-08-19 15:14:22 +03:00
|
|
|
RefPtr<gfxTextRun> textRun = aFontGroup->
|
2015-12-16 00:56:41 +03:00
|
|
|
MakeTextRun(&aChar, 1, aDrawTarget, aAppUnitsPerDevPixel, 0, nullptr);
|
2014-04-23 17:57:42 +04:00
|
|
|
const gfxTextRun::CompressedGlyph& data = textRun->GetCharacterGlyphs()[0];
|
|
|
|
if (data.IsSimpleGlyph()) {
|
|
|
|
mGlyphID = data.GetSimpleGlyph();
|
|
|
|
} else if (data.GetGlyphCount() == 1) {
|
|
|
|
mGlyphID = textRun->GetDetailedGlyphs(0)->mGlyphID;
|
|
|
|
} else {
|
|
|
|
mGlyphID = 0;
|
|
|
|
}
|
|
|
|
mCharCache = aChar;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* virtual */
|
|
|
|
nsGlyphCode
|
2015-12-16 00:56:41 +03:00
|
|
|
nsOpenTypeTable::ElementAt(DrawTarget* aDrawTarget,
|
2014-04-23 17:57:42 +04:00
|
|
|
int32_t aAppUnitsPerDevPixel,
|
|
|
|
gfxFontGroup* aFontGroup,
|
|
|
|
char16_t aChar,
|
|
|
|
bool aVertical,
|
|
|
|
uint32_t aPosition)
|
|
|
|
{
|
2015-12-16 00:56:41 +03:00
|
|
|
UpdateCache(aDrawTarget, aAppUnitsPerDevPixel, aFontGroup, aChar);
|
2014-04-23 17:57:42 +04:00
|
|
|
|
|
|
|
uint32_t parts[4];
|
|
|
|
if (!mFontEntry->GetMathVariantsParts(mGlyphID, aVertical, parts)) {
|
|
|
|
return kNullGlyph;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t glyphID = parts[aPosition];
|
|
|
|
if (!glyphID) {
|
|
|
|
return kNullGlyph;
|
|
|
|
}
|
|
|
|
nsGlyphCode glyph;
|
|
|
|
glyph.glyphID = glyphID;
|
|
|
|
glyph.font = -1;
|
|
|
|
return glyph;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* virtual */
|
|
|
|
nsGlyphCode
|
2015-12-16 00:56:41 +03:00
|
|
|
nsOpenTypeTable::BigOf(DrawTarget* aDrawTarget,
|
2014-04-23 17:57:42 +04:00
|
|
|
int32_t aAppUnitsPerDevPixel,
|
|
|
|
gfxFontGroup* aFontGroup,
|
|
|
|
char16_t aChar,
|
|
|
|
bool aVertical,
|
|
|
|
uint32_t aSize)
|
|
|
|
{
|
2015-12-16 00:56:41 +03:00
|
|
|
UpdateCache(aDrawTarget, aAppUnitsPerDevPixel, aFontGroup, aChar);
|
2014-04-23 17:57:42 +04:00
|
|
|
|
|
|
|
uint32_t glyphID =
|
|
|
|
mFontEntry->GetMathVariantsSize(mGlyphID, aVertical, aSize);
|
|
|
|
if (!glyphID) {
|
|
|
|
return kNullGlyph;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsGlyphCode glyph;
|
|
|
|
glyph.glyphID = glyphID;
|
|
|
|
glyph.font = -1;
|
|
|
|
return glyph;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* virtual */
|
|
|
|
bool
|
2015-12-16 00:56:41 +03:00
|
|
|
nsOpenTypeTable::HasPartsOf(DrawTarget* aDrawTarget,
|
2014-04-23 17:57:42 +04:00
|
|
|
int32_t aAppUnitsPerDevPixel,
|
|
|
|
gfxFontGroup* aFontGroup,
|
|
|
|
char16_t aChar,
|
|
|
|
bool aVertical)
|
|
|
|
{
|
2015-12-16 00:56:41 +03:00
|
|
|
UpdateCache(aDrawTarget, aAppUnitsPerDevPixel, aFontGroup, aChar);
|
2014-04-23 17:57:42 +04:00
|
|
|
|
|
|
|
uint32_t parts[4];
|
|
|
|
if (!mFontEntry->GetMathVariantsParts(mGlyphID, aVertical, parts)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return parts[0] || parts[1] || parts[2] || parts[3];
|
|
|
|
}
|
|
|
|
|
|
|
|
/* virtual */
|
2016-08-19 15:14:22 +03:00
|
|
|
already_AddRefed<gfxTextRun>
|
2015-12-16 00:56:41 +03:00
|
|
|
nsOpenTypeTable::MakeTextRun(DrawTarget* aDrawTarget,
|
2014-04-23 17:57:42 +04:00
|
|
|
int32_t aAppUnitsPerDevPixel,
|
|
|
|
gfxFontGroup* aFontGroup,
|
|
|
|
const nsGlyphCode& aGlyph)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(aGlyph.IsGlyphID(),
|
|
|
|
"nsOpenTypeTable can only access glyphs by id");
|
|
|
|
|
|
|
|
gfxTextRunFactory::Parameters params = {
|
2015-12-16 00:56:41 +03:00
|
|
|
aDrawTarget, nullptr, nullptr, nullptr, 0, aAppUnitsPerDevPixel
|
2014-04-23 17:57:42 +04:00
|
|
|
};
|
2016-08-19 15:14:22 +03:00
|
|
|
RefPtr<gfxTextRun> textRun =
|
2016-04-19 19:13:28 +03:00
|
|
|
gfxTextRun::Create(¶ms, 1, aFontGroup, 0);
|
2014-09-25 07:16:53 +04:00
|
|
|
textRun->AddGlyphRun(aFontGroup->GetFirstValidFont(),
|
|
|
|
gfxTextRange::kFontGroup, 0,
|
2014-09-16 15:25:45 +04:00
|
|
|
false, gfxTextRunFactory::TEXT_ORIENT_HORIZONTAL);
|
|
|
|
// We don't care about CSS writing mode here;
|
|
|
|
// math runs are assumed to be horizontal.
|
2014-04-23 17:57:42 +04:00
|
|
|
gfxTextRun::DetailedGlyph detailedGlyph;
|
|
|
|
detailedGlyph.mGlyphID = aGlyph.glyphID;
|
2014-04-23 17:57:42 +04:00
|
|
|
detailedGlyph.mAdvance =
|
|
|
|
NSToCoordRound(aAppUnitsPerDevPixel *
|
2014-09-25 07:16:53 +04:00
|
|
|
aFontGroup->GetFirstValidFont()->
|
2015-12-16 00:56:41 +03:00
|
|
|
GetGlyphHAdvance(aDrawTarget, aGlyph.glyphID));
|
2014-04-23 17:57:42 +04:00
|
|
|
detailedGlyph.mXOffset = detailedGlyph.mYOffset = 0;
|
|
|
|
gfxShapedText::CompressedGlyph g;
|
|
|
|
g.SetComplex(true, true, 1);
|
|
|
|
textRun->SetGlyphs(0, g, &detailedGlyph);
|
|
|
|
|
2016-08-19 15:14:22 +03:00
|
|
|
return textRun.forget();
|
2014-04-23 17:57:42 +04:00
|
|
|
}
|
|
|
|
|
2012-08-10 19:29:59 +04:00
|
|
|
// -----------------------------------------------------------------------------
|
2001-02-02 12:40:53 +03:00
|
|
|
// This is the list of all the applicable glyph tables.
|
2001-05-08 12:36:02 +04:00
|
|
|
// We will maintain a single global instance that will only reveal those
|
2001-02-02 12:40:53 +03:00
|
|
|
// glyph tables that are associated to fonts currently installed on the
|
|
|
|
// user' system. The class is an XPCOM shutdown observer to allow us to
|
|
|
|
// free its allocated data at shutdown
|
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
class nsGlyphTableList final : public nsIObserver
|
2001-02-02 12:40:53 +03:00
|
|
|
{
|
2000-05-08 11:18:10 +04:00
|
|
|
public:
|
2001-02-02 12:40:53 +03:00
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
NS_DECL_NSIOBSERVER
|
|
|
|
|
2014-04-23 17:57:42 +04:00
|
|
|
nsPropertiesTable mUnicodeTable;
|
2001-02-02 12:40:53 +03:00
|
|
|
|
|
|
|
nsGlyphTableList()
|
2007-12-05 06:58:09 +03:00
|
|
|
: mUnicodeTable(NS_LITERAL_STRING("Unicode"))
|
2000-03-28 13:38:24 +04:00
|
|
|
{
|
2001-02-02 12:40:53 +03:00
|
|
|
MOZ_COUNT_CTOR(nsGlyphTableList);
|
2000-03-28 13:38:24 +04:00
|
|
|
}
|
|
|
|
|
2001-02-02 12:40:53 +03:00
|
|
|
nsresult Initialize();
|
|
|
|
nsresult Finalize();
|
2000-03-28 13:38:24 +04:00
|
|
|
|
2002-01-08 05:15:23 +03:00
|
|
|
// Add a glyph table in the list, return the new table that was added
|
|
|
|
nsGlyphTable*
|
|
|
|
AddGlyphTable(const nsString& aPrimaryFontName);
|
2000-05-08 11:18:10 +04:00
|
|
|
|
2007-12-05 06:58:09 +03:00
|
|
|
// Find the glyph table in the list corresponding to the given font family.
|
|
|
|
nsGlyphTable*
|
|
|
|
GetGlyphTableFor(const nsAString& aFamily);
|
2001-03-30 06:39:38 +04:00
|
|
|
|
2000-05-08 11:18:10 +04:00
|
|
|
private:
|
2014-06-25 11:28:00 +04:00
|
|
|
~nsGlyphTableList()
|
|
|
|
{
|
|
|
|
MOZ_COUNT_DTOR(nsGlyphTableList);
|
|
|
|
}
|
|
|
|
|
2014-04-23 17:57:42 +04:00
|
|
|
nsPropertiesTable* PropertiesTableAt(int32_t aIndex) {
|
|
|
|
return &mPropertiesTableList.ElementAt(aIndex);
|
2007-12-05 06:58:09 +03:00
|
|
|
}
|
2014-04-23 17:57:42 +04:00
|
|
|
int32_t PropertiesTableCount() {
|
|
|
|
return mPropertiesTableList.Length();
|
2007-12-05 06:58:09 +03:00
|
|
|
}
|
|
|
|
// List of glyph tables;
|
2014-04-23 17:57:42 +04:00
|
|
|
nsTArray<nsPropertiesTable> mPropertiesTableList;
|
2000-03-28 13:38:24 +04:00
|
|
|
};
|
|
|
|
|
2014-04-27 11:06:00 +04:00
|
|
|
NS_IMPL_ISUPPORTS(nsGlyphTableList, nsIObserver)
|
2001-02-02 12:40:53 +03:00
|
|
|
|
2012-08-10 19:29:59 +04:00
|
|
|
// -----------------------------------------------------------------------------
|
2001-02-02 12:40:53 +03:00
|
|
|
// Here is the global list of applicable glyph tables that we will be using
|
2012-07-30 18:20:58 +04:00
|
|
|
static nsGlyphTableList* gGlyphTableList = nullptr;
|
2001-02-02 12:40:53 +03:00
|
|
|
|
2013-11-15 06:45:38 +04:00
|
|
|
static bool gGlyphTableInitialized = false;
|
2001-02-02 12:40:53 +03:00
|
|
|
|
|
|
|
// XPCOM shutdown observer
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsGlyphTableList::Observe(nsISupports* aSubject,
|
2001-10-20 02:30:02 +04:00
|
|
|
const char* aTopic,
|
2014-01-04 19:02:17 +04:00
|
|
|
const char16_t* someData)
|
2000-03-28 13:38:24 +04:00
|
|
|
{
|
2001-02-02 12:40:53 +03:00
|
|
|
Finalize();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Add an observer to XPCOM shutdown so that we can free our data at shutdown
|
|
|
|
nsresult
|
|
|
|
nsGlyphTableList::Initialize()
|
|
|
|
{
|
Bug 560095 - Use mozilla::services::GetObserverService(). r=biesi,dveditz,gavin,josh,jst,mrbkap,roc,sdwilsh,shaver,sicking,smontagu,surkov
2010-04-29 20:59:13 +04:00
|
|
|
nsCOMPtr<nsIObserverService> obs = mozilla::services::GetObserverService();
|
|
|
|
if (!obs)
|
|
|
|
return NS_ERROR_FAILURE;
|
2007-12-05 06:58:09 +03:00
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
nsresult rv = obs->AddObserver(this, NS_XPCOM_SHUTDOWN_OBSERVER_ID, false);
|
2007-12-05 06:58:09 +03:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
return NS_OK;
|
2001-02-02 12:40:53 +03:00
|
|
|
}
|
2000-03-28 13:38:24 +04:00
|
|
|
|
2001-02-02 12:40:53 +03:00
|
|
|
// Remove our observer and free the memory that were allocated for us
|
|
|
|
nsresult
|
|
|
|
nsGlyphTableList::Finalize()
|
|
|
|
{
|
|
|
|
// Remove our observer from the observer service
|
|
|
|
nsresult rv = NS_OK;
|
Bug 560095 - Use mozilla::services::GetObserverService(). r=biesi,dveditz,gavin,josh,jst,mrbkap,roc,sdwilsh,shaver,sicking,smontagu,surkov
2010-04-29 20:59:13 +04:00
|
|
|
nsCOMPtr<nsIObserverService> obs = mozilla::services::GetObserverService();
|
|
|
|
if (obs)
|
2001-10-20 02:30:02 +04:00
|
|
|
rv = obs->RemoveObserver(this, NS_XPCOM_SHUTDOWN_OBSERVER_ID);
|
Bug 560095 - Use mozilla::services::GetObserverService(). r=biesi,dveditz,gavin,josh,jst,mrbkap,roc,sdwilsh,shaver,sicking,smontagu,surkov
2010-04-29 20:59:13 +04:00
|
|
|
else
|
|
|
|
rv = NS_ERROR_FAILURE;
|
|
|
|
|
2013-11-15 06:45:38 +04:00
|
|
|
gGlyphTableInitialized = false;
|
2001-02-02 12:40:53 +03:00
|
|
|
// our oneself will be destroyed when our |Release| is called by the observer
|
2014-06-25 11:28:00 +04:00
|
|
|
NS_IF_RELEASE(gGlyphTableList);
|
2001-02-02 12:40:53 +03:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2002-01-08 05:15:23 +03:00
|
|
|
nsGlyphTable*
|
|
|
|
nsGlyphTableList::AddGlyphTable(const nsString& aPrimaryFontName)
|
2001-02-02 12:40:53 +03:00
|
|
|
{
|
2007-12-05 06:58:09 +03:00
|
|
|
// See if there is already a special table for this family.
|
|
|
|
nsGlyphTable* glyphTable = GetGlyphTableFor(aPrimaryFontName);
|
|
|
|
if (glyphTable != &mUnicodeTable)
|
|
|
|
return glyphTable;
|
2002-01-08 05:15:23 +03:00
|
|
|
|
2007-12-05 06:58:09 +03:00
|
|
|
// allocate a table
|
2014-04-23 17:57:42 +04:00
|
|
|
glyphTable = mPropertiesTableList.AppendElement(aPrimaryFontName);
|
2002-01-08 05:15:23 +03:00
|
|
|
return glyphTable;
|
2000-03-28 13:38:24 +04:00
|
|
|
}
|
|
|
|
|
2007-12-05 06:58:09 +03:00
|
|
|
nsGlyphTable*
|
|
|
|
nsGlyphTableList::GetGlyphTableFor(const nsAString& aFamily)
|
2001-02-02 12:40:53 +03:00
|
|
|
{
|
2014-04-23 17:57:42 +04:00
|
|
|
for (int32_t i = 0; i < PropertiesTableCount(); i++) {
|
|
|
|
nsPropertiesTable* glyphTable = PropertiesTableAt(i);
|
2014-06-06 10:09:23 +04:00
|
|
|
const FontFamilyName& primaryFontName = glyphTable->PrimaryFontName();
|
|
|
|
nsAutoString primaryFontNameStr;
|
|
|
|
primaryFontName.AppendToString(primaryFontNameStr);
|
2007-12-05 06:58:09 +03:00
|
|
|
// TODO: would be nice to consider StripWhitespace and other aliasing
|
2014-06-06 10:09:23 +04:00
|
|
|
if (primaryFontNameStr.Equals(aFamily, nsCaseInsensitiveStringComparator())) {
|
2007-12-05 06:58:09 +03:00
|
|
|
return glyphTable;
|
2001-02-02 12:40:53 +03:00
|
|
|
}
|
|
|
|
}
|
2007-12-05 06:58:09 +03:00
|
|
|
// Fall back to default Unicode table
|
|
|
|
return &mUnicodeTable;
|
2001-03-30 06:39:38 +04:00
|
|
|
}
|
|
|
|
|
2012-08-10 19:29:59 +04:00
|
|
|
// -----------------------------------------------------------------------------
|
2000-03-28 13:38:24 +04:00
|
|
|
|
2001-02-02 12:40:53 +03:00
|
|
|
static nsresult
|
2015-12-07 04:15:53 +03:00
|
|
|
InitCharGlobals()
|
2000-05-26 09:56:23 +04:00
|
|
|
{
|
2013-11-15 06:45:38 +04:00
|
|
|
NS_ASSERTION(!gGlyphTableInitialized, "Error -- already initialized");
|
|
|
|
gGlyphTableInitialized = true;
|
2003-04-22 07:32:06 +04:00
|
|
|
|
2001-02-02 12:40:53 +03:00
|
|
|
// Allocate the placeholders for the preferred parts and variants
|
|
|
|
nsresult rv = NS_ERROR_OUT_OF_MEMORY;
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<nsGlyphTableList> glyphTableList = new nsGlyphTableList();
|
2014-06-25 11:28:00 +04:00
|
|
|
if (glyphTableList) {
|
|
|
|
rv = glyphTableList->Initialize();
|
2001-02-02 12:40:53 +03:00
|
|
|
}
|
2003-04-23 05:08:40 +04:00
|
|
|
if (NS_FAILED(rv)) {
|
2001-02-02 12:40:53 +03:00
|
|
|
return rv;
|
|
|
|
}
|
2014-04-24 10:41:00 +04:00
|
|
|
// The gGlyphTableList has been successfully registered as a shutdown
|
|
|
|
// observer and will be deleted at shutdown. We now add some private
|
|
|
|
// per font-family tables for stretchy operators, in order of preference.
|
|
|
|
// Do not include the Unicode table in this list.
|
2015-06-12 17:43:00 +03:00
|
|
|
if (!glyphTableList->AddGlyphTable(NS_LITERAL_STRING("STIXGeneral"))
|
2014-04-24 10:41:00 +04:00
|
|
|
#ifdef XP_WIN
|
2014-06-25 11:28:00 +04:00
|
|
|
|| !glyphTableList->AddGlyphTable(NS_LITERAL_STRING("Symbol"))
|
2014-04-24 10:41:00 +04:00
|
|
|
#endif
|
|
|
|
) {
|
|
|
|
rv = NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
|
2014-06-25 11:28:00 +04:00
|
|
|
glyphTableList.forget(&gGlyphTableList);
|
2001-02-02 12:40:53 +03:00
|
|
|
return rv;
|
2000-05-26 09:56:23 +04:00
|
|
|
}
|
2000-03-30 03:15:07 +04:00
|
|
|
|
2012-08-10 19:29:59 +04:00
|
|
|
// -----------------------------------------------------------------------------
|
2000-03-28 13:38:24 +04:00
|
|
|
// And now the implementation of nsMathMLChar
|
|
|
|
|
2013-08-31 01:37:12 +04:00
|
|
|
nsMathMLChar::~nsMathMLChar()
|
|
|
|
{
|
|
|
|
MOZ_COUNT_DTOR(nsMathMLChar);
|
|
|
|
mStyleContext->Release();
|
|
|
|
}
|
|
|
|
|
2003-02-22 03:32:13 +03:00
|
|
|
nsStyleContext*
|
|
|
|
nsMathMLChar::GetStyleContext() const
|
2000-03-28 13:38:24 +04:00
|
|
|
{
|
2010-07-07 17:33:52 +04:00
|
|
|
NS_ASSERTION(mStyleContext, "chars should always have style context");
|
2003-02-22 03:32:13 +03:00
|
|
|
return mStyleContext;
|
2000-03-28 13:38:24 +04:00
|
|
|
}
|
1999-12-10 16:02:23 +03:00
|
|
|
|
2003-02-22 03:32:13 +03:00
|
|
|
void
|
|
|
|
nsMathMLChar::SetStyleContext(nsStyleContext* aStyleContext)
|
2000-03-28 13:38:24 +04:00
|
|
|
{
|
|
|
|
NS_PRECONDITION(aStyleContext, "null ptr");
|
|
|
|
if (aStyleContext != mStyleContext) {
|
2003-02-22 03:32:13 +03:00
|
|
|
if (mStyleContext)
|
|
|
|
mStyleContext->Release();
|
2000-03-28 13:38:24 +04:00
|
|
|
if (aStyleContext) {
|
|
|
|
mStyleContext = aStyleContext;
|
2003-02-22 03:32:13 +03:00
|
|
|
aStyleContext->AddRef();
|
2000-03-28 13:38:24 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
1999-11-17 03:49:37 +03:00
|
|
|
|
|
|
|
void
|
2015-12-07 04:15:53 +03:00
|
|
|
nsMathMLChar::SetData(nsString& aData)
|
2000-03-28 13:38:24 +04:00
|
|
|
{
|
2013-11-15 06:45:38 +04:00
|
|
|
if (!gGlyphTableInitialized) {
|
2015-12-07 04:15:53 +03:00
|
|
|
InitCharGlobals();
|
2000-03-28 13:38:24 +04:00
|
|
|
}
|
1999-12-10 16:02:23 +03:00
|
|
|
mData = aData;
|
2001-02-02 12:40:53 +03:00
|
|
|
// some assumptions until proven otherwise
|
2000-03-28 13:38:24 +04:00
|
|
|
// note that mGlyph is not initialized
|
1999-12-10 16:02:23 +03:00
|
|
|
mDirection = NS_STRETCH_DIRECTION_UNSUPPORTED;
|
2011-04-08 05:04:40 +04:00
|
|
|
mBoundingMetrics = nsBoundingMetrics();
|
2001-02-02 12:40:53 +03:00
|
|
|
// check if stretching is applicable ...
|
|
|
|
if (gGlyphTableList && (1 == mData.Length())) {
|
2009-11-22 00:11:05 +03:00
|
|
|
mDirection = nsMathMLOperators::GetStretchyDirection(mData);
|
|
|
|
// default tentative table (not the one that is necessarily going
|
|
|
|
// to be used)
|
1999-12-10 16:02:23 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-08-10 19:29:59 +04:00
|
|
|
// -----------------------------------------------------------------------------
|
1999-11-17 03:49:37 +03:00
|
|
|
/*
|
|
|
|
The Stretch:
|
|
|
|
@param aContainerSize - suggested size for the stretched char
|
2001-02-02 12:40:53 +03:00
|
|
|
@param aDesiredStretchSize - OUT parameter. The desired size
|
|
|
|
after stretching. If no stretching is done, the output will
|
|
|
|
simply give the base size.
|
1999-11-17 03:49:37 +03:00
|
|
|
|
|
|
|
How it works?
|
2001-02-02 12:40:53 +03:00
|
|
|
Summary:-
|
1999-11-17 03:49:37 +03:00
|
|
|
The Stretch() method first looks for a glyph of appropriate
|
2001-02-02 12:40:53 +03:00
|
|
|
size; If a glyph is found, it is cached by this object and
|
|
|
|
its size is returned in aDesiredStretchSize. The cached
|
1999-11-17 03:49:37 +03:00
|
|
|
glyph will then be used at the painting stage.
|
2001-02-02 12:40:53 +03:00
|
|
|
If no glyph of appropriate size is found, a search is made
|
|
|
|
to see if the char can be built by parts.
|
|
|
|
|
|
|
|
Details:-
|
|
|
|
A character gets stretched through the following pipeline :
|
|
|
|
|
|
|
|
1) If the base size of the char is sufficient to cover the
|
|
|
|
container' size, we use that. If not, it will still be
|
|
|
|
used as a fallback if the other stages in the pipeline fail.
|
|
|
|
Issues :
|
|
|
|
a) The base size, the parts and the variants of a char can
|
|
|
|
be in different fonts. For eg., the base size for '(' should
|
|
|
|
come from a normal ascii font if CMEX10 is used, since CMEX10
|
|
|
|
only contains the stretched versions. Hence, there are two
|
|
|
|
style contexts in use throughout the process. The leaf style
|
|
|
|
context of the char holds fonts with which to try to stretch
|
|
|
|
the char. The parent style context of the char contains fonts
|
|
|
|
for normal rendering. So the parent context is the one used
|
|
|
|
to get the initial base size at the start of the pipeline.
|
|
|
|
b) For operators that can be largeop's in display mode,
|
|
|
|
we will skip the base size even if it fits, so that
|
|
|
|
the next stage in the pipeline is given a chance to find
|
|
|
|
a largeop variant. If the next stage fails, we fallback
|
|
|
|
to the base size.
|
|
|
|
|
|
|
|
2) We search for the first larger variant of the char that fits the
|
2007-12-05 06:58:09 +03:00
|
|
|
container' size. We first search for larger variants using the glyph
|
|
|
|
table corresponding to the first existing font specified in the list of
|
|
|
|
stretchy fonts held by the leaf style context (from -moz-math-stretchy in
|
|
|
|
mathml.css). Generic fonts are resolved by the preference
|
|
|
|
"font.mathfont-family".
|
2001-02-02 12:40:53 +03:00
|
|
|
Issues :
|
|
|
|
a) the largeop and display settings determine the starting
|
|
|
|
size when we do the above search, regardless of whether
|
|
|
|
smaller variants already fit the container' size.
|
|
|
|
b) if it is a largeopOnly request (i.e., a displaystyle operator
|
|
|
|
with largeop=true and stretchy=false), we break after finding
|
|
|
|
the first starting variant, regardless of whether that
|
|
|
|
variant fits the container's size.
|
|
|
|
|
|
|
|
3) If a variant of appropriate size wasn't found, we see if the char
|
2007-12-05 06:58:09 +03:00
|
|
|
can be built by parts using the same glyph table.
|
2012-08-21 04:14:20 +04:00
|
|
|
Issue:
|
|
|
|
There are chars that have no middle and glue glyphs. For
|
2001-02-02 12:40:53 +03:00
|
|
|
such chars, the parts need to be joined using the rule.
|
|
|
|
By convention (TeXbook p.225), the descent of the parts is
|
|
|
|
zero while their ascent gives the thickness of the rule that
|
|
|
|
should be used to join them.
|
|
|
|
|
2007-12-05 06:58:09 +03:00
|
|
|
4) If a match was not found in that glyph table, repeat from 2 to search the
|
|
|
|
ordered list of stretchy fonts for the first font with a glyph table that
|
|
|
|
provides a fit to the container size. If no fit is found, the closest fit
|
|
|
|
is used.
|
|
|
|
|
2001-02-02 12:40:53 +03:00
|
|
|
Of note:
|
|
|
|
When the pipeline completes successfully, the desired size of the
|
2010-08-20 07:44:07 +04:00
|
|
|
stretched char can actually be slightly larger or smaller than
|
2001-02-02 12:40:53 +03:00
|
|
|
aContainerSize. But it is the responsibility of the caller to
|
|
|
|
account for the spacing when setting aContainerSize, and to leave
|
|
|
|
any extra margin when placing the stretched char.
|
1999-11-17 03:49:37 +03:00
|
|
|
*/
|
2012-08-10 19:29:59 +04:00
|
|
|
// -----------------------------------------------------------------------------
|
1999-11-17 03:49:37 +03:00
|
|
|
|
2000-03-28 13:38:24 +04:00
|
|
|
|
2001-02-02 12:40:53 +03:00
|
|
|
// plain TeX settings (TeXbook p.152)
|
2007-02-07 10:46:44 +03:00
|
|
|
#define NS_MATHML_DELIMITER_FACTOR 0.901f
|
|
|
|
#define NS_MATHML_DELIMITER_SHORTFALL_POINTS 5.0f
|
2001-02-02 12:40:53 +03:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
static bool
|
2015-12-07 04:15:53 +03:00
|
|
|
IsSizeOK(nscoord a, nscoord b, uint32_t aHint)
|
2000-03-28 13:38:24 +04:00
|
|
|
{
|
2001-02-02 12:40:53 +03:00
|
|
|
// Normal: True if 'a' is around +/-10% of the target 'b' (10% is
|
|
|
|
// 1-DelimiterFactor). This often gives a chance to the base size to
|
2001-03-23 12:46:24 +03:00
|
|
|
// win, especially in the context of <mfenced> without tall elements
|
2001-02-02 12:40:53 +03:00
|
|
|
// or in sloppy markups without protective <mrow></mrow>
|
2011-09-29 10:19:26 +04:00
|
|
|
bool isNormal =
|
2013-03-10 02:20:04 +04:00
|
|
|
(aHint & NS_STRETCH_NORMAL) &&
|
|
|
|
Abs<float>(a - b) < (1.0f - NS_MATHML_DELIMITER_FACTOR) * float(b);
|
|
|
|
|
2001-02-02 12:40:53 +03:00
|
|
|
// Nearer: True if 'a' is around max{ +/-10% of 'b' , 'b' - 5pt },
|
|
|
|
// as documented in The TeXbook, Ch.17, p.152.
|
2007-12-05 06:58:09 +03:00
|
|
|
// i.e. within 10% and within 5pt
|
2011-09-29 10:19:26 +04:00
|
|
|
bool isNearer = false;
|
2001-02-02 12:40:53 +03:00
|
|
|
if (aHint & (NS_STRETCH_NEARER | NS_STRETCH_LARGEOP)) {
|
2013-01-15 16:22:03 +04:00
|
|
|
float c = std::max(float(b) * NS_MATHML_DELIMITER_FACTOR,
|
2012-08-10 19:29:59 +04:00
|
|
|
float(b) - nsPresContext::
|
|
|
|
CSSPointsToAppUnits(NS_MATHML_DELIMITER_SHORTFALL_POINTS));
|
2013-03-10 02:20:04 +04:00
|
|
|
isNearer = Abs<float>(b - a) <= float(b) - c;
|
2001-02-02 12:40:53 +03:00
|
|
|
}
|
2013-03-10 02:20:04 +04:00
|
|
|
|
2001-02-02 12:40:53 +03:00
|
|
|
// Smaller: Mainly for transitory use, to compare two candidate
|
|
|
|
// choices
|
2011-09-29 10:19:26 +04:00
|
|
|
bool isSmaller =
|
2013-03-10 02:20:04 +04:00
|
|
|
(aHint & NS_STRETCH_SMALLER) &&
|
|
|
|
float(a) >= NS_MATHML_DELIMITER_FACTOR * float(b) &&
|
|
|
|
a <= b;
|
|
|
|
|
2001-02-02 12:40:53 +03:00
|
|
|
// Larger: Critical to the sqrt code to ensure that the radical
|
|
|
|
// size is tall enough
|
2011-09-29 10:19:26 +04:00
|
|
|
bool isLarger =
|
2013-03-10 02:20:04 +04:00
|
|
|
(aHint & (NS_STRETCH_LARGER | NS_STRETCH_LARGEOP)) &&
|
|
|
|
a >= b;
|
|
|
|
|
2001-02-02 12:40:53 +03:00
|
|
|
return (isNormal || isSmaller || isNearer || isLarger);
|
2000-03-28 13:38:24 +04:00
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
static bool
|
2012-08-22 19:56:38 +04:00
|
|
|
IsSizeBetter(nscoord a, nscoord olda, nscoord b, uint32_t aHint)
|
2000-03-28 13:38:24 +04:00
|
|
|
{
|
2007-12-05 06:58:09 +03:00
|
|
|
if (0 == olda)
|
2011-10-17 18:59:28 +04:00
|
|
|
return true;
|
2007-12-05 06:58:09 +03:00
|
|
|
if (aHint & (NS_STRETCH_LARGER | NS_STRETCH_LARGEOP))
|
|
|
|
return (a >= olda) ? (olda < b) : (a >= b);
|
|
|
|
if (aHint & NS_STRETCH_SMALLER)
|
|
|
|
return (a <= olda) ? (olda > b) : (a <= b);
|
|
|
|
|
|
|
|
// XXXkt prob want log scale here i.e. 1.5 is closer to 1 than 0.5
|
2013-03-10 02:20:04 +04:00
|
|
|
return Abs(a - b) < Abs(olda - b);
|
2000-03-28 13:38:24 +04:00
|
|
|
}
|
|
|
|
|
2001-03-23 12:46:24 +03:00
|
|
|
// We want to place the glyphs even when they don't fit at their
|
|
|
|
// full extent, i.e., we may clip to tolerate a small amount of
|
|
|
|
// overlap between the parts. This is important to cater for fonts
|
|
|
|
// with long glues.
|
|
|
|
static nscoord
|
2007-02-07 10:46:44 +03:00
|
|
|
ComputeSizeFromParts(nsPresContext* aPresContext,
|
|
|
|
nsGlyphCode* aGlyphs,
|
2001-02-02 12:40:53 +03:00
|
|
|
nscoord* aSizes,
|
2008-04-23 07:13:09 +04:00
|
|
|
nscoord aTargetSize)
|
2001-02-02 12:40:53 +03:00
|
|
|
{
|
2001-03-23 12:46:24 +03:00
|
|
|
enum {first, middle, last, glue};
|
2008-01-03 07:21:36 +03:00
|
|
|
// Add the parts that cannot be left out.
|
|
|
|
nscoord sum = 0;
|
2012-08-22 19:56:38 +04:00
|
|
|
for (int32_t i = first; i <= last; i++) {
|
2016-01-29 03:36:00 +03:00
|
|
|
sum += aSizes[i];
|
2008-01-03 07:21:36 +03:00
|
|
|
}
|
|
|
|
|
2008-04-23 07:13:09 +04:00
|
|
|
// Determine how much is used in joins
|
|
|
|
nscoord oneDevPixel = aPresContext->AppUnitsPerDevPixel();
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t joins = aGlyphs[middle] == aGlyphs[glue] ? 1 : 2;
|
2008-01-03 07:21:36 +03:00
|
|
|
|
|
|
|
// Pick a maximum size using a maximum number of glue glyphs that we are
|
|
|
|
// prepared to draw for one character.
|
2012-08-22 19:56:38 +04:00
|
|
|
const int32_t maxGlyphs = 1000;
|
2008-04-23 07:13:09 +04:00
|
|
|
|
2008-01-03 07:21:36 +03:00
|
|
|
// This also takes into account the fact that, if the glue has no size,
|
|
|
|
// then the character can't be lengthened.
|
2008-04-23 07:13:09 +04:00
|
|
|
nscoord maxSize = sum - 2 * joins * oneDevPixel + maxGlyphs * aSizes[glue];
|
2008-01-03 07:21:36 +03:00
|
|
|
if (maxSize < aTargetSize)
|
|
|
|
return maxSize; // settle with the maximum size
|
|
|
|
|
2008-04-23 07:13:09 +04:00
|
|
|
// Get the minimum allowable size using some flex.
|
|
|
|
nscoord minSize = NSToCoordRound(NS_MATHML_DELIMITER_FACTOR * sum);
|
|
|
|
|
|
|
|
if (minSize > aTargetSize)
|
|
|
|
return minSize; // settle with the minimum size
|
|
|
|
|
2008-01-03 07:21:36 +03:00
|
|
|
// Fill-up the target area
|
|
|
|
return aTargetSize;
|
2007-12-05 06:58:09 +03:00
|
|
|
}
|
|
|
|
|
2014-02-13 18:53:52 +04:00
|
|
|
// Update the font if there is a family change and returns the font group.
|
|
|
|
bool
|
|
|
|
nsMathMLChar::SetFontFamily(nsPresContext* aPresContext,
|
|
|
|
const nsGlyphTable* aGlyphTable,
|
|
|
|
const nsGlyphCode& aGlyphCode,
|
2014-06-06 10:09:23 +04:00
|
|
|
const FontFamilyList& aDefaultFamilyList,
|
2014-02-13 18:53:52 +04:00
|
|
|
nsFont& aFont,
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<gfxFontGroup>* aFontGroup)
|
2000-04-17 08:19:54 +04:00
|
|
|
{
|
2014-06-06 10:09:23 +04:00
|
|
|
FontFamilyList glyphCodeFont;
|
|
|
|
|
|
|
|
if (aGlyphCode.font) {
|
|
|
|
glyphCodeFont.Append(aGlyphTable->FontNameFor(aGlyphCode));
|
|
|
|
}
|
|
|
|
|
|
|
|
const FontFamilyList& familyList =
|
|
|
|
aGlyphCode.font ? glyphCodeFont : aDefaultFamilyList;
|
|
|
|
|
|
|
|
if (!*aFontGroup || !(aFont.fontlist == familyList)) {
|
2012-03-26 19:49:44 +04:00
|
|
|
nsFont font = aFont;
|
2014-06-06 10:09:23 +04:00
|
|
|
font.fontlist = familyList;
|
2014-12-23 15:50:10 +03:00
|
|
|
const nsStyleFont* styleFont = mStyleContext->StyleFont();
|
2016-03-21 06:59:36 +03:00
|
|
|
nsFontMetrics::Params params;
|
|
|
|
params.language = styleFont->mLanguage;
|
|
|
|
params.explicitLanguage = styleFont->mExplicitLanguage;
|
|
|
|
params.userFontSet = aPresContext->GetUserFontSet();
|
|
|
|
params.textPerf = aPresContext->GetTextPerfMetrics();
|
2016-03-17 08:55:48 +03:00
|
|
|
RefPtr<nsFontMetrics> fm =
|
|
|
|
aPresContext->DeviceContext()->GetMetricsFor(font, params);
|
2012-03-26 19:49:44 +04:00
|
|
|
// Set the font if it is an unicode table
|
|
|
|
// or if the same family name has been found
|
2014-09-25 07:16:53 +04:00
|
|
|
gfxFont *firstFont = fm->GetThebesFontGroup()->GetFirstValidFont();
|
2014-06-06 10:09:23 +04:00
|
|
|
FontFamilyList firstFontList;
|
2014-10-06 18:14:49 +04:00
|
|
|
firstFontList.Append(
|
|
|
|
FontFamilyName(firstFont->GetFontEntry()->FamilyName(), eUnquotedName));
|
2012-03-26 19:49:44 +04:00
|
|
|
if (aGlyphTable == &gGlyphTableList->mUnicodeTable ||
|
2014-06-06 10:09:23 +04:00
|
|
|
firstFontList == familyList) {
|
|
|
|
aFont.fontlist = familyList;
|
2014-02-13 18:53:52 +04:00
|
|
|
*aFontGroup = fm->GetThebesFontGroup();
|
2012-12-19 13:42:25 +04:00
|
|
|
} else {
|
|
|
|
return false; // We did not set the font
|
|
|
|
}
|
2007-12-05 06:58:09 +03:00
|
|
|
}
|
2012-03-26 19:49:44 +04:00
|
|
|
return true;
|
2007-12-05 06:58:09 +03:00
|
|
|
}
|
|
|
|
|
2014-02-13 18:53:52 +04:00
|
|
|
static nsBoundingMetrics
|
2015-12-16 00:56:41 +03:00
|
|
|
MeasureTextRun(DrawTarget* aDrawTarget, gfxTextRun* aTextRun)
|
2014-02-13 18:53:52 +04:00
|
|
|
{
|
|
|
|
gfxTextRun::Metrics metrics =
|
2016-03-08 10:56:18 +03:00
|
|
|
aTextRun->MeasureText(gfxFont::TIGHT_HINTED_OUTLINE_EXTENTS, aDrawTarget);
|
2014-02-13 18:53:52 +04:00
|
|
|
|
|
|
|
nsBoundingMetrics bm;
|
|
|
|
bm.leftBearing = NSToCoordFloor(metrics.mBoundingBox.X());
|
|
|
|
bm.rightBearing = NSToCoordCeil(metrics.mBoundingBox.XMost());
|
|
|
|
bm.ascent = NSToCoordCeil(-metrics.mBoundingBox.Y());
|
|
|
|
bm.descent = NSToCoordCeil(metrics.mBoundingBox.YMost());
|
|
|
|
bm.width = NSToCoordRound(metrics.mAdvanceWidth);
|
|
|
|
|
|
|
|
return bm;
|
|
|
|
}
|
|
|
|
|
2008-03-14 07:05:43 +03:00
|
|
|
class nsMathMLChar::StretchEnumContext {
|
|
|
|
public:
|
|
|
|
StretchEnumContext(nsMathMLChar* aChar,
|
|
|
|
nsPresContext* aPresContext,
|
2015-12-16 00:56:41 +03:00
|
|
|
DrawTarget* aDrawTarget,
|
2014-10-25 10:30:00 +04:00
|
|
|
float aFontSizeInflation,
|
2008-03-14 07:05:43 +03:00
|
|
|
nsStretchDirection aStretchDirection,
|
|
|
|
nscoord aTargetSize,
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t aStretchHint,
|
2008-03-14 07:05:43 +03:00
|
|
|
nsBoundingMetrics& aStretchedMetrics,
|
2014-06-06 10:09:23 +04:00
|
|
|
const FontFamilyList& aFamilyList,
|
2011-09-29 10:19:26 +04:00
|
|
|
bool& aGlyphFound)
|
2008-03-14 07:05:43 +03:00
|
|
|
: mChar(aChar),
|
|
|
|
mPresContext(aPresContext),
|
2015-12-16 00:56:41 +03:00
|
|
|
mDrawTarget(aDrawTarget),
|
2014-10-25 10:30:00 +04:00
|
|
|
mFontSizeInflation(aFontSizeInflation),
|
2008-03-14 07:05:43 +03:00
|
|
|
mDirection(aStretchDirection),
|
|
|
|
mTargetSize(aTargetSize),
|
|
|
|
mStretchHint(aStretchHint),
|
|
|
|
mBoundingMetrics(aStretchedMetrics),
|
2014-06-06 10:09:23 +04:00
|
|
|
mFamilyList(aFamilyList),
|
2011-10-17 18:59:28 +04:00
|
|
|
mTryVariants(true),
|
|
|
|
mTryParts(true),
|
2011-03-25 06:38:59 +03:00
|
|
|
mGlyphFound(aGlyphFound) {}
|
2008-03-14 07:05:43 +03:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
static bool
|
2014-06-06 10:09:23 +04:00
|
|
|
EnumCallback(const FontFamilyName& aFamily, bool aGeneric, void *aData);
|
2008-03-14 07:05:43 +03:00
|
|
|
|
|
|
|
private:
|
2014-04-23 17:57:42 +04:00
|
|
|
bool TryVariants(nsGlyphTable* aGlyphTable,
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<gfxFontGroup>* aFontGroup,
|
2014-06-06 10:09:23 +04:00
|
|
|
const FontFamilyList& aFamilyList);
|
2014-04-23 17:57:42 +04:00
|
|
|
bool TryParts(nsGlyphTable* aGlyphTable,
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<gfxFontGroup>* aFontGroup,
|
2014-06-06 10:09:23 +04:00
|
|
|
const FontFamilyList& aFamilyList);
|
2008-03-14 07:05:43 +03:00
|
|
|
|
|
|
|
nsMathMLChar* mChar;
|
|
|
|
nsPresContext* mPresContext;
|
2015-12-16 00:56:41 +03:00
|
|
|
DrawTarget* mDrawTarget;
|
2014-10-25 10:30:00 +04:00
|
|
|
float mFontSizeInflation;
|
2008-03-14 07:05:43 +03:00
|
|
|
const nsStretchDirection mDirection;
|
|
|
|
const nscoord mTargetSize;
|
2012-08-22 19:56:38 +04:00
|
|
|
const uint32_t mStretchHint;
|
2008-03-14 07:05:43 +03:00
|
|
|
nsBoundingMetrics& mBoundingMetrics;
|
|
|
|
// Font families to search
|
2014-06-06 10:09:23 +04:00
|
|
|
const FontFamilyList& mFamilyList;
|
2008-03-14 07:05:43 +03:00
|
|
|
|
|
|
|
public:
|
2011-09-29 10:19:26 +04:00
|
|
|
bool mTryVariants;
|
|
|
|
bool mTryParts;
|
2008-03-14 07:05:43 +03:00
|
|
|
|
|
|
|
private:
|
2016-02-02 18:36:30 +03:00
|
|
|
AutoTArray<nsGlyphTable*,16> mTablesTried;
|
2011-09-29 10:19:26 +04:00
|
|
|
bool& mGlyphFound;
|
2008-03-14 07:05:43 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2007-12-05 06:58:09 +03:00
|
|
|
// 2. See if there are any glyphs of the appropriate size.
|
2011-10-17 18:59:28 +04:00
|
|
|
// Returns true if the size is OK, false to keep searching.
|
2007-12-05 06:58:09 +03:00
|
|
|
// Always updates the char if a better match is found.
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2014-04-23 17:57:42 +04:00
|
|
|
nsMathMLChar::
|
|
|
|
StretchEnumContext::TryVariants(nsGlyphTable* aGlyphTable,
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<gfxFontGroup>* aFontGroup,
|
2014-06-06 10:09:23 +04:00
|
|
|
const FontFamilyList& aFamilyList)
|
2007-12-05 06:58:09 +03:00
|
|
|
{
|
|
|
|
// Use our stretchy style context now that stretching is in progress
|
2011-08-14 21:08:04 +04:00
|
|
|
nsStyleContext *sc = mChar->mStyleContext;
|
2013-02-17 01:51:02 +04:00
|
|
|
nsFont font = sc->StyleFont()->mFont;
|
2014-10-25 10:30:00 +04:00
|
|
|
NormalizeDefaultFont(font, mFontSizeInflation);
|
2007-12-05 06:58:09 +03:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool isVertical = (mDirection == NS_STRETCH_DIRECTION_VERTICAL);
|
2014-04-23 17:57:42 +04:00
|
|
|
nscoord oneDevPixel = mPresContext->AppUnitsPerDevPixel();
|
|
|
|
char16_t uchar = mChar->mData[0];
|
2011-09-29 10:19:26 +04:00
|
|
|
bool largeop = (NS_STRETCH_LARGEOP & mStretchHint) != 0;
|
|
|
|
bool largeopOnly =
|
2008-03-14 07:05:43 +03:00
|
|
|
largeop && (NS_STRETCH_VARIABLE_MASK & mStretchHint) == 0;
|
2011-09-29 10:19:26 +04:00
|
|
|
bool maxWidth = (NS_STRETCH_MAXWIDTH & mStretchHint) != 0;
|
2007-12-05 06:58:09 +03:00
|
|
|
|
|
|
|
nscoord bestSize =
|
|
|
|
isVertical ? mBoundingMetrics.ascent + mBoundingMetrics.descent
|
|
|
|
: mBoundingMetrics.rightBearing - mBoundingMetrics.leftBearing;
|
2011-09-29 10:19:26 +04:00
|
|
|
bool haveBetter = false;
|
2007-12-05 06:58:09 +03:00
|
|
|
|
2011-06-22 19:48:56 +04:00
|
|
|
// start at size = 1 (size = 0 is the char at its normal size)
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t size = 1;
|
2014-04-23 17:57:42 +04:00
|
|
|
nsGlyphCode ch;
|
|
|
|
nscoord displayOperatorMinHeight = 0;
|
|
|
|
if (largeopOnly) {
|
|
|
|
NS_ASSERTION(isVertical, "Stretching should be in the vertical direction");
|
2015-12-16 00:56:41 +03:00
|
|
|
ch = aGlyphTable->BigOf(mDrawTarget, oneDevPixel, *aFontGroup, uchar,
|
2014-04-23 17:57:42 +04:00
|
|
|
isVertical, 0);
|
|
|
|
if (ch.IsGlyphID()) {
|
2014-07-02 07:29:00 +04:00
|
|
|
gfxFont* mathFont = aFontGroup->get()->GetFirstMathFont();
|
2014-04-23 17:57:42 +04:00
|
|
|
// For OpenType MATH fonts, we will rely on the DisplayOperatorMinHeight
|
|
|
|
// to select the right size variant. Note that the value is sometimes too
|
|
|
|
// small so we use kLargeOpFactor/kIntegralFactor as a minimum value.
|
2014-07-02 07:29:00 +04:00
|
|
|
if (mathFont) {
|
|
|
|
displayOperatorMinHeight =
|
|
|
|
mathFont->GetMathConstant(gfxFontEntry::DisplayOperatorMinHeight,
|
|
|
|
oneDevPixel);
|
2016-08-19 15:14:22 +03:00
|
|
|
RefPtr<gfxTextRun> textRun =
|
2016-04-19 19:13:28 +03:00
|
|
|
aGlyphTable->MakeTextRun(mDrawTarget, oneDevPixel, *aFontGroup, ch);
|
|
|
|
nsBoundingMetrics bm = MeasureTextRun(mDrawTarget, textRun.get());
|
2014-07-02 07:29:00 +04:00
|
|
|
float largeopFactor = kLargeOpFactor;
|
|
|
|
if (NS_STRETCH_INTEGRAL & mStretchHint) {
|
|
|
|
// integrals are drawn taller
|
|
|
|
largeopFactor = kIntegralFactor;
|
|
|
|
}
|
|
|
|
nscoord minHeight = largeopFactor * (bm.ascent + bm.descent);
|
|
|
|
if (displayOperatorMinHeight < minHeight) {
|
|
|
|
displayOperatorMinHeight = minHeight;
|
|
|
|
}
|
2014-04-23 17:57:42 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2007-12-05 06:58:09 +03:00
|
|
|
#ifdef NOISY_SEARCH
|
|
|
|
printf(" searching in %s ...\n",
|
|
|
|
NS_LossyConvertUTF16toASCII(aFamily).get());
|
|
|
|
#endif
|
2015-12-16 00:56:41 +03:00
|
|
|
while ((ch = aGlyphTable->BigOf(mDrawTarget, oneDevPixel, *aFontGroup,
|
2014-04-23 17:57:42 +04:00
|
|
|
uchar, isVertical, size)).Exists()) {
|
2007-12-05 06:58:09 +03:00
|
|
|
|
2014-06-06 10:09:23 +04:00
|
|
|
if (!mChar->SetFontFamily(mPresContext, aGlyphTable, ch, aFamilyList, font,
|
2014-04-23 17:57:42 +04:00
|
|
|
aFontGroup)) {
|
2012-03-26 19:49:44 +04:00
|
|
|
// if largeopOnly is set, break now
|
|
|
|
if (largeopOnly) break;
|
|
|
|
++size;
|
|
|
|
continue;
|
|
|
|
}
|
2007-12-05 06:58:09 +03:00
|
|
|
|
2016-08-19 15:14:22 +03:00
|
|
|
RefPtr<gfxTextRun> textRun =
|
2016-04-19 19:13:28 +03:00
|
|
|
aGlyphTable->MakeTextRun(mDrawTarget, oneDevPixel, *aFontGroup, ch);
|
|
|
|
nsBoundingMetrics bm = MeasureTextRun(mDrawTarget, textRun.get());
|
2014-04-23 17:57:42 +04:00
|
|
|
if (ch.IsGlyphID()) {
|
2014-07-02 07:29:00 +04:00
|
|
|
gfxFont* mathFont = aFontGroup->get()->GetFirstMathFont();
|
|
|
|
if (mathFont) {
|
2014-04-23 17:57:42 +04:00
|
|
|
// MeasureTextRun should have set the advance width to the right
|
|
|
|
// bearing for OpenType MATH fonts. We now subtract the italic
|
|
|
|
// correction, so that nsMathMLmmultiscripts will place the scripts
|
|
|
|
// correctly.
|
|
|
|
// Note that STIX-Word does not provide italic corrections but its
|
|
|
|
// advance widths do not match right bearings.
|
2014-04-23 17:57:42 +04:00
|
|
|
// (http://sourceforge.net/p/stixfonts/tracking/50/)
|
|
|
|
gfxFloat italicCorrection;
|
|
|
|
if (mathFont->GetFontEntry()->
|
|
|
|
GetMathItalicsCorrection(ch.glyphID, &italicCorrection)) {
|
|
|
|
bm.width -=
|
|
|
|
NSToCoordRound(italicCorrection *
|
|
|
|
mathFont->GetAdjustedSize() * oneDevPixel);
|
|
|
|
if (bm.width < 0) {
|
|
|
|
bm.width = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2007-12-05 06:58:09 +03:00
|
|
|
|
2011-04-08 05:04:40 +04:00
|
|
|
nscoord charSize =
|
|
|
|
isVertical ? bm.ascent + bm.descent
|
|
|
|
: bm.rightBearing - bm.leftBearing;
|
|
|
|
|
|
|
|
if (largeopOnly ||
|
|
|
|
IsSizeBetter(charSize, bestSize, mTargetSize, mStretchHint)) {
|
2011-10-17 18:59:28 +04:00
|
|
|
mGlyphFound = true;
|
2011-04-08 05:04:40 +04:00
|
|
|
if (maxWidth) {
|
|
|
|
// IsSizeBetter() checked that charSize < maxsize;
|
|
|
|
// Leave ascent, descent, and bestsize as these contain maxsize.
|
|
|
|
if (mBoundingMetrics.width < bm.width)
|
|
|
|
mBoundingMetrics.width = bm.width;
|
|
|
|
if (mBoundingMetrics.leftBearing > bm.leftBearing)
|
|
|
|
mBoundingMetrics.leftBearing = bm.leftBearing;
|
|
|
|
if (mBoundingMetrics.rightBearing < bm.rightBearing)
|
|
|
|
mBoundingMetrics.rightBearing = bm.rightBearing;
|
|
|
|
// Continue to check other sizes unless largeopOnly
|
|
|
|
haveBetter = largeopOnly;
|
2007-12-05 06:58:09 +03:00
|
|
|
}
|
|
|
|
else {
|
2011-04-08 05:04:40 +04:00
|
|
|
mBoundingMetrics = bm;
|
2011-10-17 18:59:28 +04:00
|
|
|
haveBetter = true;
|
2011-04-08 05:04:40 +04:00
|
|
|
bestSize = charSize;
|
2016-04-19 19:13:28 +03:00
|
|
|
mChar->mGlyphs[0] = Move(textRun);
|
2014-02-13 18:53:52 +04:00
|
|
|
mChar->mDraw = DRAW_VARIANT;
|
2011-04-08 05:04:40 +04:00
|
|
|
}
|
2007-12-05 06:58:09 +03:00
|
|
|
#ifdef NOISY_SEARCH
|
2011-04-08 05:04:40 +04:00
|
|
|
printf(" size:%d Current best\n", size);
|
2007-12-05 06:58:09 +03:00
|
|
|
#endif
|
2011-04-08 05:04:40 +04:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
#ifdef NOISY_SEARCH
|
|
|
|
printf(" size:%d Rejected!\n", size);
|
|
|
|
#endif
|
|
|
|
if (haveBetter)
|
|
|
|
break; // Not making an futher progress, stop searching
|
2007-12-05 06:58:09 +03:00
|
|
|
}
|
|
|
|
|
2014-04-23 17:57:42 +04:00
|
|
|
// If this a largeop only operator, we stop if the glyph is large enough.
|
|
|
|
if (largeopOnly && (bm.ascent + bm.descent) >= displayOperatorMinHeight) {
|
|
|
|
break;
|
|
|
|
}
|
2007-12-05 06:58:09 +03:00
|
|
|
++size;
|
|
|
|
}
|
|
|
|
|
|
|
|
return haveBetter &&
|
2015-12-07 04:15:53 +03:00
|
|
|
(largeopOnly || IsSizeOK(bestSize, mTargetSize, mStretchHint));
|
2007-12-05 06:58:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// 3. Build by parts.
|
2011-10-17 18:59:28 +04:00
|
|
|
// Returns true if the size is OK, false to keep searching.
|
2007-12-05 06:58:09 +03:00
|
|
|
// Always updates the char if a better match is found.
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2014-04-23 17:57:42 +04:00
|
|
|
nsMathMLChar::StretchEnumContext::TryParts(nsGlyphTable* aGlyphTable,
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<gfxFontGroup>* aFontGroup,
|
2014-06-06 10:09:23 +04:00
|
|
|
const FontFamilyList& aFamilyList)
|
2007-12-05 06:58:09 +03:00
|
|
|
{
|
|
|
|
// Use our stretchy style context now that stretching is in progress
|
2013-02-17 01:51:02 +04:00
|
|
|
nsFont font = mChar->mStyleContext->StyleFont()->mFont;
|
2014-10-25 10:30:00 +04:00
|
|
|
NormalizeDefaultFont(font, mFontSizeInflation);
|
2007-12-05 06:58:09 +03:00
|
|
|
|
|
|
|
// Compute the bounding metrics of all partial glyphs
|
2016-08-19 15:14:22 +03:00
|
|
|
RefPtr<gfxTextRun> textRun[4];
|
2007-12-05 06:58:09 +03:00
|
|
|
nsGlyphCode chdata[4];
|
|
|
|
nsBoundingMetrics bmdata[4];
|
|
|
|
nscoord sizedata[4];
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool isVertical = (mDirection == NS_STRETCH_DIRECTION_VERTICAL);
|
2014-04-23 17:57:42 +04:00
|
|
|
nscoord oneDevPixel = mPresContext->AppUnitsPerDevPixel();
|
|
|
|
char16_t uchar = mChar->mData[0];
|
2011-09-29 10:19:26 +04:00
|
|
|
bool maxWidth = (NS_STRETCH_MAXWIDTH & mStretchHint) != 0;
|
2015-12-16 00:56:41 +03:00
|
|
|
if (!aGlyphTable->HasPartsOf(mDrawTarget, oneDevPixel, *aFontGroup,
|
2014-04-23 17:57:42 +04:00
|
|
|
uchar, isVertical))
|
|
|
|
return false; // to next table
|
2007-12-05 06:58:09 +03:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
for (int32_t i = 0; i < 4; i++) {
|
2015-12-16 00:56:41 +03:00
|
|
|
nsGlyphCode ch = aGlyphTable->ElementAt(mDrawTarget, oneDevPixel,
|
2014-04-23 17:57:42 +04:00
|
|
|
*aFontGroup, uchar, isVertical, i);
|
2008-01-03 07:21:36 +03:00
|
|
|
chdata[i] = ch;
|
2014-02-13 18:53:52 +04:00
|
|
|
if (ch.Exists()) {
|
2014-06-06 10:09:23 +04:00
|
|
|
if (!mChar->SetFontFamily(mPresContext, aGlyphTable, ch, aFamilyList, font,
|
2014-04-23 17:57:42 +04:00
|
|
|
aFontGroup))
|
2012-03-26 19:49:44 +04:00
|
|
|
return false;
|
|
|
|
|
2015-12-16 00:56:41 +03:00
|
|
|
textRun[i] = aGlyphTable->MakeTextRun(mDrawTarget, oneDevPixel,
|
2014-04-23 17:57:42 +04:00
|
|
|
*aFontGroup, ch);
|
2016-04-19 19:13:28 +03:00
|
|
|
nsBoundingMetrics bm = MeasureTextRun(mDrawTarget, textRun[i].get());
|
2008-01-03 07:21:36 +03:00
|
|
|
bmdata[i] = bm;
|
|
|
|
sizedata[i] = isVertical ? bm.ascent + bm.descent
|
|
|
|
: bm.rightBearing - bm.leftBearing;
|
2014-02-13 18:53:52 +04:00
|
|
|
} else {
|
|
|
|
// Null glue indicates that a rule will be drawn, which can stretch to
|
|
|
|
// fill any space.
|
|
|
|
textRun[i] = nullptr;
|
|
|
|
bmdata[i] = nsBoundingMetrics();
|
|
|
|
sizedata[i] = i == 3 ? mTargetSize : 0;
|
2007-12-05 06:58:09 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-08 07:25:00 +04:00
|
|
|
// For the Unicode table, we check that all the glyphs are actually found and
|
|
|
|
// come from the same font.
|
|
|
|
if (aGlyphTable == &gGlyphTableList->mUnicodeTable) {
|
|
|
|
gfxFont* unicodeFont = nullptr;
|
|
|
|
for (int32_t i = 0; i < 4; i++) {
|
|
|
|
if (!textRun[i]) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (textRun[i]->GetLength() != 1 ||
|
|
|
|
textRun[i]->GetCharacterGlyphs()[0].IsMissing()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
uint32_t numGlyphRuns;
|
|
|
|
const gfxTextRun::GlyphRun* glyphRuns =
|
|
|
|
textRun[i]->GetGlyphRuns(&numGlyphRuns);
|
|
|
|
if (numGlyphRuns != 1) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (!unicodeFont) {
|
|
|
|
unicodeFont = glyphRuns[0].mFont;
|
|
|
|
} else if (unicodeFont != glyphRuns[0].mFont) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-12-05 06:58:09 +03:00
|
|
|
// Build by parts if we have successfully computed the
|
|
|
|
// bounding metrics of all parts.
|
2008-03-14 07:05:43 +03:00
|
|
|
nscoord computedSize = ComputeSizeFromParts(mPresContext, chdata, sizedata,
|
2008-04-23 07:13:09 +04:00
|
|
|
mTargetSize);
|
2007-12-05 06:58:09 +03:00
|
|
|
|
|
|
|
nscoord currentSize =
|
|
|
|
isVertical ? mBoundingMetrics.ascent + mBoundingMetrics.descent
|
|
|
|
: mBoundingMetrics.rightBearing - mBoundingMetrics.leftBearing;
|
|
|
|
|
2008-03-14 07:05:43 +03:00
|
|
|
if (!IsSizeBetter(computedSize, currentSize, mTargetSize, mStretchHint)) {
|
2007-12-05 06:58:09 +03:00
|
|
|
#ifdef NOISY_SEARCH
|
|
|
|
printf(" Font %s Rejected!\n",
|
|
|
|
NS_LossyConvertUTF16toASCII(fontName).get());
|
|
|
|
#endif
|
2011-10-17 18:59:28 +04:00
|
|
|
return false; // to next table
|
2007-12-05 06:58:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef NOISY_SEARCH
|
|
|
|
printf(" Font %s Current best!\n",
|
|
|
|
NS_LossyConvertUTF16toASCII(fontName).get());
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// The computed size is the best we have found so far...
|
|
|
|
// now is the time to compute and cache our bounding metrics
|
|
|
|
if (isVertical) {
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t i;
|
2014-02-13 18:53:52 +04:00
|
|
|
// Try and find the first existing part and then determine the extremal
|
|
|
|
// horizontal metrics of the parts.
|
|
|
|
for (i = 0; i <= 3 && !textRun[i]; i++);
|
|
|
|
if (i == 4) {
|
|
|
|
NS_ERROR("Cannot stretch - All parts missing");
|
|
|
|
return false;
|
2008-03-14 07:05:43 +03:00
|
|
|
}
|
2014-02-13 18:53:52 +04:00
|
|
|
nscoord lbearing = bmdata[i].leftBearing;
|
|
|
|
nscoord rbearing = bmdata[i].rightBearing;
|
|
|
|
nscoord width = bmdata[i].width;
|
|
|
|
i++;
|
|
|
|
for (; i <= 3; i++) {
|
|
|
|
if (!textRun[i]) continue;
|
|
|
|
lbearing = std::min(lbearing, bmdata[i].leftBearing);
|
|
|
|
rbearing = std::max(rbearing, bmdata[i].rightBearing);
|
|
|
|
width = std::max(width, bmdata[i].width);
|
2008-03-14 07:05:43 +03:00
|
|
|
}
|
2014-02-13 18:53:52 +04:00
|
|
|
if (maxWidth) {
|
|
|
|
lbearing = std::min(lbearing, mBoundingMetrics.leftBearing);
|
|
|
|
rbearing = std::max(rbearing, mBoundingMetrics.rightBearing);
|
|
|
|
width = std::max(width, mBoundingMetrics.width);
|
2007-12-05 06:58:09 +03:00
|
|
|
}
|
|
|
|
mBoundingMetrics.width = width;
|
2008-03-14 07:05:43 +03:00
|
|
|
// When maxWidth, updating ascent and descent indicates that no characters
|
|
|
|
// larger than this character's minimum size need to be checked as they
|
|
|
|
// will not be used.
|
2012-08-10 19:29:59 +04:00
|
|
|
mBoundingMetrics.ascent = bmdata[0].ascent; // not used except with descent
|
|
|
|
// for height
|
2007-12-05 06:58:09 +03:00
|
|
|
mBoundingMetrics.descent = computedSize - mBoundingMetrics.ascent;
|
|
|
|
mBoundingMetrics.leftBearing = lbearing;
|
|
|
|
mBoundingMetrics.rightBearing = rbearing;
|
|
|
|
}
|
|
|
|
else {
|
2014-02-13 18:53:52 +04:00
|
|
|
int32_t i;
|
|
|
|
// Try and find the first existing part and then determine the extremal
|
|
|
|
// vertical metrics of the parts.
|
|
|
|
for (i = 0; i <= 3 && !textRun[i]; i++);
|
|
|
|
if (i == 4) {
|
|
|
|
NS_ERROR("Cannot stretch - All parts missing");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
nscoord ascent = bmdata[i].ascent;
|
|
|
|
nscoord descent = bmdata[i].descent;
|
|
|
|
i++;
|
|
|
|
for (; i <= 3; i++) {
|
|
|
|
if (!textRun[i]) continue;
|
|
|
|
ascent = std::max(ascent, bmdata[i].ascent);
|
|
|
|
descent = std::max(descent, bmdata[i].descent);
|
2007-12-05 06:58:09 +03:00
|
|
|
}
|
|
|
|
mBoundingMetrics.width = computedSize;
|
|
|
|
mBoundingMetrics.ascent = ascent;
|
|
|
|
mBoundingMetrics.descent = descent;
|
|
|
|
mBoundingMetrics.leftBearing = 0;
|
|
|
|
mBoundingMetrics.rightBearing = computedSize;
|
|
|
|
}
|
2011-10-17 18:59:28 +04:00
|
|
|
mGlyphFound = true;
|
2008-03-14 07:05:43 +03:00
|
|
|
if (maxWidth)
|
2011-10-17 18:59:28 +04:00
|
|
|
return false; // Continue to check other sizes
|
2008-03-14 07:05:43 +03:00
|
|
|
|
2007-12-05 06:58:09 +03:00
|
|
|
// reset
|
2014-02-13 18:53:52 +04:00
|
|
|
mChar->mDraw = DRAW_PARTS;
|
|
|
|
for (int32_t i = 0; i < 4; i++) {
|
2016-04-19 19:13:28 +03:00
|
|
|
mChar->mGlyphs[i] = Move(textRun[i]);
|
2014-02-13 18:53:52 +04:00
|
|
|
mChar->mBmData[i] = bmdata[i];
|
|
|
|
}
|
2007-12-05 06:58:09 +03:00
|
|
|
|
2015-12-07 04:15:53 +03:00
|
|
|
return IsSizeOK(computedSize, mTargetSize, mStretchHint);
|
2007-12-05 06:58:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// This is called for each family, whether it exists or not
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2014-06-06 10:09:23 +04:00
|
|
|
nsMathMLChar::StretchEnumContext::EnumCallback(const FontFamilyName& aFamily,
|
2011-09-29 10:19:26 +04:00
|
|
|
bool aGeneric, void *aData)
|
2007-12-05 06:58:09 +03:00
|
|
|
{
|
|
|
|
StretchEnumContext* context = static_cast<StretchEnumContext*>(aData);
|
|
|
|
|
2014-06-06 10:09:24 +04:00
|
|
|
// for comparisons, force use of unquoted names
|
|
|
|
FontFamilyName unquotedFamilyName(aFamily);
|
|
|
|
if (unquotedFamilyName.mType == eFamily_named_quoted) {
|
|
|
|
unquotedFamilyName.mType = eFamily_named;
|
|
|
|
}
|
|
|
|
|
2012-03-26 19:49:44 +04:00
|
|
|
// Check font family if it is not a generic one
|
|
|
|
// We test with the kNullGlyph
|
|
|
|
nsStyleContext *sc = context->mChar->mStyleContext;
|
2013-02-17 01:51:02 +04:00
|
|
|
nsFont font = sc->StyleFont()->mFont;
|
2014-10-25 10:30:00 +04:00
|
|
|
NormalizeDefaultFont(font, context->mFontSizeInflation);
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<gfxFontGroup> fontGroup;
|
2014-06-06 10:09:23 +04:00
|
|
|
FontFamilyList family;
|
2014-06-06 10:09:24 +04:00
|
|
|
family.Append(unquotedFamilyName);
|
2014-02-13 18:53:52 +04:00
|
|
|
if (!aGeneric && !context->mChar->SetFontFamily(context->mPresContext,
|
2014-06-06 10:09:23 +04:00
|
|
|
nullptr, kNullGlyph, family,
|
2014-02-13 18:53:52 +04:00
|
|
|
font, &fontGroup))
|
2012-03-26 19:49:44 +04:00
|
|
|
return true; // Could not set the family
|
|
|
|
|
2014-04-23 17:57:42 +04:00
|
|
|
// Determine the glyph table to use for this font.
|
|
|
|
nsAutoPtr<nsOpenTypeTable> openTypeTable;
|
|
|
|
nsGlyphTable* glyphTable;
|
|
|
|
if (aGeneric) {
|
|
|
|
// This is a generic font, use the Unicode table.
|
|
|
|
glyphTable = &gGlyphTableList->mUnicodeTable;
|
|
|
|
} else {
|
|
|
|
// If the font contains an Open Type MATH table, use it.
|
2014-09-25 07:16:53 +04:00
|
|
|
openTypeTable = nsOpenTypeTable::Create(fontGroup->GetFirstValidFont());
|
2014-04-23 17:57:42 +04:00
|
|
|
if (openTypeTable) {
|
|
|
|
glyphTable = openTypeTable;
|
|
|
|
} else {
|
|
|
|
// Otherwise try to find a .properties file corresponding to that font
|
|
|
|
// family or fallback to the Unicode table.
|
2014-06-06 10:09:23 +04:00
|
|
|
nsAutoString familyName;
|
2014-06-06 10:09:24 +04:00
|
|
|
unquotedFamilyName.AppendToString(familyName);
|
2014-06-06 10:09:23 +04:00
|
|
|
glyphTable = gGlyphTableList->GetGlyphTableFor(familyName);
|
2014-04-23 17:57:42 +04:00
|
|
|
}
|
|
|
|
}
|
2012-03-26 19:49:44 +04:00
|
|
|
|
2014-04-23 17:57:42 +04:00
|
|
|
if (!openTypeTable) {
|
|
|
|
if (context->mTablesTried.Contains(glyphTable))
|
|
|
|
return true; // already tried this one
|
|
|
|
|
|
|
|
// Only try this table once.
|
|
|
|
context->mTablesTried.AppendElement(glyphTable);
|
|
|
|
}
|
2012-03-26 19:49:44 +04:00
|
|
|
|
|
|
|
// If the unicode table is being used, then search all font families. If a
|
|
|
|
// special table is being used then the font in this family should have the
|
|
|
|
// specified glyphs.
|
2014-06-06 10:09:23 +04:00
|
|
|
const FontFamilyList& familyList = glyphTable == &gGlyphTableList->mUnicodeTable ?
|
|
|
|
context->mFamilyList : family;
|
2012-03-26 19:49:44 +04:00
|
|
|
|
2014-04-23 17:57:42 +04:00
|
|
|
if((context->mTryVariants &&
|
2014-06-06 10:09:23 +04:00
|
|
|
context->TryVariants(glyphTable, &fontGroup, familyList)) ||
|
|
|
|
(context->mTryParts && context->TryParts(glyphTable,
|
|
|
|
&fontGroup,
|
|
|
|
familyList)))
|
2012-03-26 19:49:44 +04:00
|
|
|
return false; // no need to continue
|
2007-12-05 06:58:09 +03:00
|
|
|
|
2012-03-26 19:49:44 +04:00
|
|
|
return true; // true means continue
|
2000-04-17 08:19:54 +04:00
|
|
|
}
|
|
|
|
|
2014-06-06 10:09:23 +04:00
|
|
|
// insert math fallback families just before the first generic or at the end
|
|
|
|
// when no generic present
|
|
|
|
static void
|
|
|
|
InsertMathFallbacks(FontFamilyList& aFamilyList,
|
|
|
|
nsTArray<nsString>& aFallbacks)
|
|
|
|
{
|
|
|
|
FontFamilyList aMergedList;
|
|
|
|
|
|
|
|
bool inserted = false;
|
|
|
|
const nsTArray<FontFamilyName>& fontlist = aFamilyList.GetFontlist();
|
|
|
|
uint32_t i, num = fontlist.Length();
|
|
|
|
for (i = 0; i < num; i++) {
|
|
|
|
const FontFamilyName& name = fontlist[i];
|
|
|
|
if (!inserted && name.IsGeneric()) {
|
|
|
|
inserted = true;
|
|
|
|
aMergedList.Append(aFallbacks);
|
|
|
|
}
|
|
|
|
aMergedList.Append(name);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!inserted) {
|
|
|
|
aMergedList.Append(aFallbacks);
|
|
|
|
}
|
|
|
|
aFamilyList = aMergedList;
|
|
|
|
}
|
|
|
|
|
2000-03-28 13:38:24 +04:00
|
|
|
nsresult
|
2008-03-14 07:05:43 +03:00
|
|
|
nsMathMLChar::StretchInternal(nsPresContext* aPresContext,
|
2015-12-16 00:56:41 +03:00
|
|
|
DrawTarget* aDrawTarget,
|
2014-10-25 10:30:00 +04:00
|
|
|
float aFontSizeInflation,
|
2008-03-14 07:05:43 +03:00
|
|
|
nsStretchDirection& aStretchDirection,
|
|
|
|
const nsBoundingMetrics& aContainerSize,
|
|
|
|
nsBoundingMetrics& aDesiredStretchSize,
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t aStretchHint,
|
2008-03-14 07:05:43 +03:00
|
|
|
// These are currently only used when
|
|
|
|
// aStretchHint & NS_STRETCH_MAXWIDTH:
|
|
|
|
float aMaxSize,
|
2011-09-29 10:19:26 +04:00
|
|
|
bool aMaxSizeIsAbsolute)
|
1999-09-21 06:12:01 +04:00
|
|
|
{
|
2002-02-09 01:48:38 +03:00
|
|
|
// if we have been called before, and we didn't actually stretch, our
|
|
|
|
// direction may have been set to NS_STRETCH_DIRECTION_UNSUPPORTED.
|
|
|
|
// So first set our direction back to its instrinsic value
|
2009-11-22 00:11:05 +03:00
|
|
|
nsStretchDirection direction = nsMathMLOperators::GetStretchyDirection(mData);
|
1999-11-17 03:49:37 +03:00
|
|
|
|
2001-02-02 12:40:53 +03:00
|
|
|
// Set default font and get the default bounding metrics
|
|
|
|
// mStyleContext is a leaf context used only when stretching happens.
|
|
|
|
// For the base size, the default font should come from the parent context
|
2013-02-17 01:51:02 +04:00
|
|
|
nsFont font = mStyleContext->GetParent()->StyleFont()->mFont;
|
2014-10-25 10:30:00 +04:00
|
|
|
NormalizeDefaultFont(font, aFontSizeInflation);
|
2003-04-22 07:32:06 +04:00
|
|
|
|
2014-12-23 15:50:10 +03:00
|
|
|
const nsStyleFont* styleFont = mStyleContext->StyleFont();
|
2016-03-21 06:59:36 +03:00
|
|
|
nsFontMetrics::Params params;
|
|
|
|
params.language = styleFont->mLanguage;
|
|
|
|
params.explicitLanguage = styleFont->mExplicitLanguage;
|
|
|
|
params.userFontSet = aPresContext->GetUserFontSet();
|
|
|
|
params.textPerf = aPresContext->GetTextPerfMetrics();
|
2016-03-17 08:55:48 +03:00
|
|
|
RefPtr<nsFontMetrics> fm =
|
|
|
|
aPresContext->DeviceContext()->GetMetricsFor(font, params);
|
2014-02-13 18:53:52 +04:00
|
|
|
uint32_t len = uint32_t(mData.Length());
|
2016-04-19 19:13:28 +03:00
|
|
|
mGlyphs[0] = fm->GetThebesFontGroup()->
|
2015-12-16 00:56:41 +03:00
|
|
|
MakeTextRun(static_cast<const char16_t*>(mData.get()), len, aDrawTarget,
|
2014-12-22 19:35:54 +03:00
|
|
|
aPresContext->AppUnitsPerDevPixel(), 0,
|
|
|
|
aPresContext->MissingFontRecorder());
|
2016-04-19 19:13:28 +03:00
|
|
|
aDesiredStretchSize = MeasureTextRun(aDrawTarget, mGlyphs[0].get());
|
2000-03-28 13:38:24 +04:00
|
|
|
|
2014-04-24 10:33:00 +04:00
|
|
|
bool maxWidth = (NS_STRETCH_MAXWIDTH & aStretchHint) != 0;
|
2010-08-20 07:44:07 +04:00
|
|
|
if (!maxWidth) {
|
|
|
|
mUnscaledAscent = aDesiredStretchSize.ascent;
|
|
|
|
}
|
|
|
|
|
2012-08-10 19:29:59 +04:00
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
2008-03-14 07:05:43 +03:00
|
|
|
// 1. Check the common situations where stretching is not actually needed
|
2012-08-10 19:29:59 +04:00
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
2000-03-28 13:38:24 +04:00
|
|
|
|
2001-02-02 12:40:53 +03:00
|
|
|
// quick return if there is nothing special about this char
|
2010-08-20 07:44:07 +04:00
|
|
|
if ((aStretchDirection != direction &&
|
2008-03-14 07:05:43 +03:00
|
|
|
aStretchDirection != NS_STRETCH_DIRECTION_DEFAULT) ||
|
|
|
|
(aStretchHint & ~NS_STRETCH_MAXWIDTH) == NS_STRETCH_NONE) {
|
2010-08-20 07:44:07 +04:00
|
|
|
mDirection = NS_STRETCH_DIRECTION_UNSUPPORTED;
|
1999-11-17 03:49:37 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2008-03-14 07:05:43 +03:00
|
|
|
// if no specified direction, attempt to stretch in our preferred direction
|
|
|
|
if (aStretchDirection == NS_STRETCH_DIRECTION_DEFAULT) {
|
|
|
|
aStretchDirection = direction;
|
|
|
|
}
|
|
|
|
|
2001-02-02 12:40:53 +03:00
|
|
|
// see if this is a particular largeop or largeopOnly request
|
2011-09-29 10:19:26 +04:00
|
|
|
bool largeop = (NS_STRETCH_LARGEOP & aStretchHint) != 0;
|
|
|
|
bool stretchy = (NS_STRETCH_VARIABLE_MASK & aStretchHint) != 0;
|
|
|
|
bool largeopOnly = largeop && !stretchy;
|
2001-02-02 12:40:53 +03:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool isVertical = (direction == NS_STRETCH_DIRECTION_VERTICAL);
|
2008-03-14 07:05:43 +03:00
|
|
|
|
|
|
|
nscoord targetSize =
|
|
|
|
isVertical ? aContainerSize.ascent + aContainerSize.descent
|
|
|
|
: aContainerSize.rightBearing - aContainerSize.leftBearing;
|
|
|
|
|
|
|
|
if (maxWidth) {
|
|
|
|
// See if it is only necessary to consider glyphs up to some maximum size.
|
|
|
|
// Set the current height to the maximum size, and set aStretchHint to
|
|
|
|
// NS_STRETCH_SMALLER if the size is variable, so that only smaller sizes
|
|
|
|
// are considered. targetSize from GetMaxWidth() is 0.
|
|
|
|
if (stretchy) {
|
|
|
|
// variable size stretch - consider all sizes < maxsize
|
|
|
|
aStretchHint =
|
|
|
|
(aStretchHint & ~NS_STRETCH_VARIABLE_MASK) | NS_STRETCH_SMALLER;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Use NS_MATHML_DELIMITER_FACTOR to allow some slightly larger glyphs as
|
|
|
|
// maxsize is not enforced exactly.
|
|
|
|
if (aMaxSize == NS_MATHML_OPERATOR_SIZE_INFINITY) {
|
|
|
|
aDesiredStretchSize.ascent = nscoord_MAX;
|
|
|
|
aDesiredStretchSize.descent = 0;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
nscoord height = aDesiredStretchSize.ascent + aDesiredStretchSize.descent;
|
|
|
|
if (height == 0) {
|
|
|
|
if (aMaxSizeIsAbsolute) {
|
|
|
|
aDesiredStretchSize.ascent =
|
|
|
|
NSToCoordRound(aMaxSize / NS_MATHML_DELIMITER_FACTOR);
|
|
|
|
aDesiredStretchSize.descent = 0;
|
|
|
|
}
|
|
|
|
// else: leave height as 0
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
float scale = aMaxSizeIsAbsolute ? aMaxSize / height : aMaxSize;
|
|
|
|
scale /= NS_MATHML_DELIMITER_FACTOR;
|
|
|
|
aDesiredStretchSize.ascent =
|
|
|
|
NSToCoordRound(scale * aDesiredStretchSize.ascent);
|
|
|
|
aDesiredStretchSize.descent =
|
|
|
|
NSToCoordRound(scale * aDesiredStretchSize.descent);
|
|
|
|
}
|
|
|
|
}
|
2001-02-02 12:40:53 +03:00
|
|
|
}
|
2008-03-14 07:05:43 +03:00
|
|
|
|
2010-08-20 07:44:07 +04:00
|
|
|
nsBoundingMetrics initialSize = aDesiredStretchSize;
|
|
|
|
nscoord charSize =
|
|
|
|
isVertical ? initialSize.ascent + initialSize.descent
|
|
|
|
: initialSize.rightBearing - initialSize.leftBearing;
|
2008-03-14 07:05:43 +03:00
|
|
|
|
2014-02-13 18:53:52 +04:00
|
|
|
bool done = false;
|
2010-08-20 07:44:07 +04:00
|
|
|
|
2014-02-13 18:53:52 +04:00
|
|
|
if (!maxWidth && !largeop) {
|
2010-08-20 07:44:07 +04:00
|
|
|
// Doing Stretch() not GetMaxWidth(),
|
|
|
|
// and not a largeop in display mode; we're done if size fits
|
2008-03-14 07:05:43 +03:00
|
|
|
if ((targetSize <= 0) ||
|
|
|
|
((isVertical && charSize >= targetSize) ||
|
2015-12-07 04:15:53 +03:00
|
|
|
IsSizeOK(charSize, targetSize, aStretchHint)))
|
2011-10-17 18:59:28 +04:00
|
|
|
done = true;
|
2000-03-28 13:38:24 +04:00
|
|
|
}
|
|
|
|
|
2012-08-10 19:29:59 +04:00
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
2007-12-05 06:58:09 +03:00
|
|
|
// 2/3. Search for a glyph or set of part glyphs of appropriate size
|
2012-08-10 19:29:59 +04:00
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
2000-03-28 13:38:24 +04:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool glyphFound = false;
|
2000-03-28 13:38:24 +04:00
|
|
|
|
2007-12-05 06:58:09 +03:00
|
|
|
if (!done) { // normal case
|
|
|
|
// Use the css font-family but add preferred fallback fonts.
|
2014-04-24 10:33:00 +04:00
|
|
|
font = mStyleContext->StyleFont()->mFont;
|
2014-10-25 10:30:00 +04:00
|
|
|
NormalizeDefaultFont(font, aFontSizeInflation);
|
2014-06-06 10:09:23 +04:00
|
|
|
|
|
|
|
// really shouldn't be doing things this way but for now
|
|
|
|
// insert fallbacks into the list
|
2016-02-02 18:36:30 +03:00
|
|
|
AutoTArray<nsString, 16> mathFallbacks;
|
2015-05-25 03:40:00 +03:00
|
|
|
gfxFontUtils::GetPrefsFontList("font.name.serif.x-math", mathFallbacks);
|
|
|
|
gfxFontUtils::AppendPrefsFontList("font.name-list.serif.x-math",
|
|
|
|
mathFallbacks);
|
2014-06-06 10:09:23 +04:00
|
|
|
InsertMathFallbacks(font.fontlist, mathFallbacks);
|
|
|
|
|
2001-02-02 12:40:53 +03:00
|
|
|
|
|
|
|
#ifdef NOISY_SEARCH
|
2014-06-06 10:09:23 +04:00
|
|
|
nsAutoString fontlistStr;
|
|
|
|
font.fontlist.ToString(fontlistStr, false, true);
|
2007-12-05 06:58:09 +03:00
|
|
|
printf("Searching in "%s" for a glyph of appropriate size for: 0x%04X:%c\n",
|
2014-06-06 10:09:23 +04:00
|
|
|
NS_ConvertUTF16toUTF8(fontlistStr).get(), mData[0], mData[0]&0x00FF);
|
2001-02-02 12:40:53 +03:00
|
|
|
#endif
|
2015-12-16 00:56:41 +03:00
|
|
|
StretchEnumContext enumData(this, aPresContext, aDrawTarget,
|
2014-10-25 10:30:00 +04:00
|
|
|
aFontSizeInflation,
|
2008-03-14 07:05:43 +03:00
|
|
|
aStretchDirection, targetSize, aStretchHint,
|
2014-06-06 10:09:23 +04:00
|
|
|
aDesiredStretchSize, font.fontlist, glyphFound);
|
2008-03-14 07:05:43 +03:00
|
|
|
enumData.mTryParts = !largeopOnly;
|
2007-12-05 06:58:09 +03:00
|
|
|
|
2014-06-06 10:09:23 +04:00
|
|
|
const nsTArray<FontFamilyName>& fontlist = font.fontlist.GetFontlist();
|
|
|
|
uint32_t i, num = fontlist.Length();
|
|
|
|
bool next = true;
|
|
|
|
for (i = 0; i < num && next; i++) {
|
|
|
|
const FontFamilyName& name = fontlist[i];
|
|
|
|
next = StretchEnumContext::EnumCallback(name, name.IsGeneric(), &enumData);
|
|
|
|
}
|
1999-09-21 06:12:01 +04:00
|
|
|
}
|
|
|
|
|
2010-08-20 07:44:07 +04:00
|
|
|
if (!maxWidth) {
|
|
|
|
// Now, we know how we are going to draw the char. Update the member
|
|
|
|
// variables accordingly.
|
|
|
|
mUnscaledAscent = aDesiredStretchSize.ascent;
|
|
|
|
}
|
|
|
|
|
2014-04-23 08:28:00 +04:00
|
|
|
if (glyphFound) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2014-11-11 10:37:00 +03:00
|
|
|
// We did not find a size variant or a glyph assembly to stretch this
|
|
|
|
// operator. Verify whether a font with an OpenType MATH table is available
|
|
|
|
// and record missing math script otherwise.
|
|
|
|
gfxMissingFontRecorder* MFR = aPresContext->MissingFontRecorder();
|
|
|
|
if (MFR && !fm->GetThebesFontGroup()->GetFirstMathFont()) {
|
2016-04-21 20:58:59 +03:00
|
|
|
MFR->RecordScript(unicode::Script::MATHEMATICAL_NOTATION);
|
2014-11-11 10:37:00 +03:00
|
|
|
}
|
|
|
|
|
2015-04-25 01:48:00 +03:00
|
|
|
// If the scale_stretchy_operators option is disabled, we are done.
|
|
|
|
if (!Preferences::GetBool("mathml.scale_stretchy_operators.enabled", true)) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-08-20 07:44:07 +04:00
|
|
|
// stretchy character
|
|
|
|
if (stretchy) {
|
|
|
|
if (isVertical) {
|
|
|
|
float scale =
|
2014-05-12 03:32:00 +04:00
|
|
|
std::min(kMaxScaleFactor, float(aContainerSize.ascent + aContainerSize.descent) /
|
|
|
|
(aDesiredStretchSize.ascent + aDesiredStretchSize.descent));
|
2010-08-20 07:44:07 +04:00
|
|
|
if (!largeop || scale > 1.0) {
|
|
|
|
// make the character match the desired height.
|
2011-03-25 06:38:59 +03:00
|
|
|
if (!maxWidth) {
|
|
|
|
mScaleY *= scale;
|
|
|
|
}
|
2010-08-20 07:44:07 +04:00
|
|
|
aDesiredStretchSize.ascent *= scale;
|
|
|
|
aDesiredStretchSize.descent *= scale;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
float scale =
|
2014-05-12 03:32:00 +04:00
|
|
|
std::min(kMaxScaleFactor, float(aContainerSize.rightBearing - aContainerSize.leftBearing) /
|
|
|
|
(aDesiredStretchSize.rightBearing - aDesiredStretchSize.leftBearing));
|
2010-08-20 07:44:07 +04:00
|
|
|
if (!largeop || scale > 1.0) {
|
|
|
|
// make the character match the desired width.
|
2011-03-25 06:38:59 +03:00
|
|
|
if (!maxWidth) {
|
|
|
|
mScaleX *= scale;
|
|
|
|
}
|
2010-08-20 07:44:07 +04:00
|
|
|
aDesiredStretchSize.leftBearing *= scale;
|
|
|
|
aDesiredStretchSize.rightBearing *= scale;
|
|
|
|
aDesiredStretchSize.width *= scale;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// We do not have a char variant for this largeop in display mode, so we
|
|
|
|
// apply a scale transform to the base char.
|
2014-04-23 08:28:00 +04:00
|
|
|
if (largeop) {
|
2010-08-20 07:44:07 +04:00
|
|
|
float scale;
|
2014-04-23 17:57:42 +04:00
|
|
|
float largeopFactor = kLargeOpFactor;
|
2010-08-20 07:44:07 +04:00
|
|
|
|
|
|
|
// increase the width if it is not largeopFactor times larger
|
|
|
|
// than the initial one.
|
|
|
|
if ((aDesiredStretchSize.rightBearing - aDesiredStretchSize.leftBearing) <
|
|
|
|
largeopFactor * (initialSize.rightBearing - initialSize.leftBearing)) {
|
|
|
|
scale = (largeopFactor *
|
|
|
|
(initialSize.rightBearing - initialSize.leftBearing)) /
|
|
|
|
(aDesiredStretchSize.rightBearing - aDesiredStretchSize.leftBearing);
|
2011-03-25 06:38:59 +03:00
|
|
|
if (!maxWidth) {
|
|
|
|
mScaleX *= scale;
|
|
|
|
}
|
2010-08-20 07:44:07 +04:00
|
|
|
aDesiredStretchSize.leftBearing *= scale;
|
|
|
|
aDesiredStretchSize.rightBearing *= scale;
|
|
|
|
aDesiredStretchSize.width *= scale;
|
|
|
|
}
|
|
|
|
|
|
|
|
// increase the height if it is not largeopFactor times larger
|
|
|
|
// than the initial one.
|
|
|
|
if (NS_STRETCH_INTEGRAL & aStretchHint) {
|
|
|
|
// integrals are drawn taller
|
2014-04-23 17:57:42 +04:00
|
|
|
largeopFactor = kIntegralFactor;
|
2010-08-20 07:44:07 +04:00
|
|
|
}
|
|
|
|
if ((aDesiredStretchSize.ascent + aDesiredStretchSize.descent) <
|
|
|
|
largeopFactor * (initialSize.ascent + initialSize.descent)) {
|
|
|
|
scale = (largeopFactor *
|
|
|
|
(initialSize.ascent + initialSize.descent)) /
|
|
|
|
(aDesiredStretchSize.ascent + aDesiredStretchSize.descent);
|
2011-03-25 06:38:59 +03:00
|
|
|
if (!maxWidth) {
|
|
|
|
mScaleY *= scale;
|
|
|
|
}
|
2010-08-20 07:44:07 +04:00
|
|
|
aDesiredStretchSize.ascent *= scale;
|
|
|
|
aDesiredStretchSize.descent *= scale;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-03-14 07:05:43 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsMathMLChar::Stretch(nsPresContext* aPresContext,
|
2015-12-16 00:56:41 +03:00
|
|
|
DrawTarget* aDrawTarget,
|
2014-10-25 10:30:00 +04:00
|
|
|
float aFontSizeInflation,
|
2008-03-14 07:05:43 +03:00
|
|
|
nsStretchDirection aStretchDirection,
|
|
|
|
const nsBoundingMetrics& aContainerSize,
|
|
|
|
nsBoundingMetrics& aDesiredStretchSize,
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t aStretchHint,
|
2011-12-22 02:22:00 +04:00
|
|
|
bool aRTL)
|
2008-03-14 07:05:43 +03:00
|
|
|
{
|
|
|
|
NS_ASSERTION(!(aStretchHint &
|
2010-08-20 07:44:07 +04:00
|
|
|
~(NS_STRETCH_VARIABLE_MASK | NS_STRETCH_LARGEOP |
|
|
|
|
NS_STRETCH_INTEGRAL)),
|
2008-03-14 07:05:43 +03:00
|
|
|
"Unexpected stretch flags");
|
|
|
|
|
2014-02-13 18:53:52 +04:00
|
|
|
mDraw = DRAW_NORMAL;
|
2011-12-22 02:22:00 +04:00
|
|
|
mMirrored = aRTL && nsMathMLOperators::IsMirrorableOperator(mData);
|
2011-03-25 06:38:59 +03:00
|
|
|
mScaleY = mScaleX = 1.0;
|
2008-03-14 07:05:43 +03:00
|
|
|
mDirection = aStretchDirection;
|
|
|
|
nsresult rv =
|
2015-12-16 00:56:41 +03:00
|
|
|
StretchInternal(aPresContext, aDrawTarget, aFontSizeInflation, mDirection,
|
2008-03-14 07:05:43 +03:00
|
|
|
aContainerSize, aDesiredStretchSize, aStretchHint);
|
|
|
|
|
|
|
|
// Record the metrics
|
|
|
|
mBoundingMetrics = aDesiredStretchSize;
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
// What happens here is that the StretchInternal algorithm is used but
|
|
|
|
// modified by passing the NS_STRETCH_MAXWIDTH stretch hint. That causes
|
|
|
|
// StretchInternal to return horizontal bounding metrics that are the maximum
|
|
|
|
// that might be returned from a Stretch.
|
|
|
|
//
|
|
|
|
// In order to avoid considering widths of some characters in fonts that will
|
|
|
|
// not be used for any stretch size, StretchInternal sets the initial height
|
|
|
|
// to infinity and looks for any characters smaller than this height. When a
|
|
|
|
// character built from parts is considered, (it will be used by Stretch for
|
|
|
|
// any characters greater than its minimum size, so) the height is set to its
|
|
|
|
// minimum size, so that only widths of smaller subsequent characters are
|
|
|
|
// considered.
|
|
|
|
nscoord
|
2015-12-16 00:56:41 +03:00
|
|
|
nsMathMLChar::GetMaxWidth(nsPresContext* aPresContext, DrawTarget* aDrawTarget,
|
|
|
|
float aFontSizeInflation, uint32_t aStretchHint)
|
2008-03-14 07:05:43 +03:00
|
|
|
{
|
|
|
|
nsBoundingMetrics bm;
|
|
|
|
nsStretchDirection direction = NS_STRETCH_DIRECTION_VERTICAL;
|
|
|
|
const nsBoundingMetrics container; // zero target size
|
|
|
|
|
2015-12-16 00:56:41 +03:00
|
|
|
StretchInternal(aPresContext, aDrawTarget, aFontSizeInflation, direction,
|
2014-02-13 18:53:52 +04:00
|
|
|
container, bm, aStretchHint | NS_STRETCH_MAXWIDTH);
|
2008-03-14 07:05:43 +03:00
|
|
|
|
2013-01-15 16:22:03 +04:00
|
|
|
return std::max(bm.width, bm.rightBearing) - std::min(0, bm.leftBearing);
|
1999-09-21 06:12:01 +04:00
|
|
|
}
|
|
|
|
|
2006-01-26 05:29:17 +03:00
|
|
|
class nsDisplayMathMLSelectionRect : public nsDisplayItem {
|
|
|
|
public:
|
2010-08-13 14:01:13 +04:00
|
|
|
nsDisplayMathMLSelectionRect(nsDisplayListBuilder* aBuilder,
|
|
|
|
nsIFrame* aFrame, const nsRect& aRect)
|
|
|
|
: nsDisplayItem(aBuilder, aFrame), mRect(aRect) {
|
2006-01-29 21:48:58 +03:00
|
|
|
MOZ_COUNT_CTOR(nsDisplayMathMLSelectionRect);
|
|
|
|
}
|
|
|
|
#ifdef NS_BUILD_REFCNT_LOGGING
|
|
|
|
virtual ~nsDisplayMathMLSelectionRect() {
|
|
|
|
MOZ_COUNT_DTOR(nsDisplayMathMLSelectionRect);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2009-09-07 04:35:14 +04:00
|
|
|
virtual void Paint(nsDisplayListBuilder* aBuilder,
|
2015-03-21 19:28:04 +03:00
|
|
|
nsRenderingContext* aCtx) override;
|
2010-07-16 01:07:49 +04:00
|
|
|
NS_DISPLAY_DECL_NAME("MathMLSelectionRect", TYPE_MATHML_SELECTION_RECT)
|
2006-01-26 05:29:17 +03:00
|
|
|
private:
|
|
|
|
nsRect mRect;
|
|
|
|
};
|
|
|
|
|
|
|
|
void nsDisplayMathMLSelectionRect::Paint(nsDisplayListBuilder* aBuilder,
|
2011-04-08 05:04:40 +04:00
|
|
|
nsRenderingContext* aCtx)
|
2006-01-26 05:29:17 +03:00
|
|
|
{
|
2014-10-19 16:22:22 +04:00
|
|
|
DrawTarget* drawTarget = aCtx->GetDrawTarget();
|
2014-10-22 15:29:06 +04:00
|
|
|
Rect rect = NSRectToSnappedRect(mRect + ToReferenceFrame(),
|
|
|
|
mFrame->PresContext()->AppUnitsPerDevPixel(),
|
|
|
|
*drawTarget);
|
2006-01-26 05:29:17 +03:00
|
|
|
// get color to use for selection from the look&feel object
|
2011-09-09 06:27:13 +04:00
|
|
|
nscolor bgColor =
|
|
|
|
LookAndFeel::GetColor(LookAndFeel::eColorID_TextSelectBackground,
|
|
|
|
NS_RGB(0, 0, 0));
|
2014-10-19 16:22:22 +04:00
|
|
|
drawTarget->FillRect(rect, ColorPattern(ToDeviceColor(bgColor)));
|
2006-01-26 05:29:17 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
class nsDisplayMathMLCharBackground : public nsDisplayItem {
|
|
|
|
public:
|
2010-08-13 14:01:13 +04:00
|
|
|
nsDisplayMathMLCharBackground(nsDisplayListBuilder* aBuilder,
|
|
|
|
nsIFrame* aFrame, const nsRect& aRect,
|
|
|
|
nsStyleContext* aStyleContext)
|
2012-08-10 19:29:59 +04:00
|
|
|
: nsDisplayItem(aBuilder, aFrame), mStyleContext(aStyleContext),
|
|
|
|
mRect(aRect) {
|
2006-01-29 21:48:58 +03:00
|
|
|
MOZ_COUNT_CTOR(nsDisplayMathMLCharBackground);
|
|
|
|
}
|
|
|
|
#ifdef NS_BUILD_REFCNT_LOGGING
|
|
|
|
virtual ~nsDisplayMathMLCharBackground() {
|
|
|
|
MOZ_COUNT_DTOR(nsDisplayMathMLCharBackground);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual nsDisplayItemGeometry* AllocateGeometry(nsDisplayListBuilder* aBuilder) override;
|
2013-06-26 20:43:26 +04:00
|
|
|
virtual void ComputeInvalidationRegion(nsDisplayListBuilder* aBuilder,
|
|
|
|
const nsDisplayItemGeometry* aGeometry,
|
2015-03-21 19:28:04 +03:00
|
|
|
nsRegion *aInvalidRegion) override;
|
2009-09-07 04:35:14 +04:00
|
|
|
virtual void Paint(nsDisplayListBuilder* aBuilder,
|
2015-03-21 19:28:04 +03:00
|
|
|
nsRenderingContext* aCtx) override;
|
2010-07-16 01:07:49 +04:00
|
|
|
NS_DISPLAY_DECL_NAME("MathMLCharBackground", TYPE_MATHML_CHAR_BACKGROUND)
|
2006-01-26 05:29:17 +03:00
|
|
|
private:
|
|
|
|
nsStyleContext* mStyleContext;
|
|
|
|
nsRect mRect;
|
|
|
|
};
|
|
|
|
|
2015-02-10 10:27:40 +03:00
|
|
|
nsDisplayItemGeometry*
|
|
|
|
nsDisplayMathMLCharBackground::AllocateGeometry(nsDisplayListBuilder* aBuilder)
|
|
|
|
{
|
|
|
|
return new nsDisplayItemGenericImageGeometry(this, aBuilder);
|
|
|
|
}
|
|
|
|
|
2013-06-26 20:43:26 +04:00
|
|
|
void
|
|
|
|
nsDisplayMathMLCharBackground::ComputeInvalidationRegion(nsDisplayListBuilder* aBuilder,
|
|
|
|
const nsDisplayItemGeometry* aGeometry,
|
|
|
|
nsRegion *aInvalidRegion)
|
|
|
|
{
|
2015-02-10 10:27:40 +03:00
|
|
|
auto geometry =
|
|
|
|
static_cast<const nsDisplayItemGenericImageGeometry*>(aGeometry);
|
|
|
|
|
|
|
|
if (aBuilder->ShouldSyncDecodeImages() &&
|
|
|
|
geometry->ShouldInvalidateToSyncDecodeImages()) {
|
|
|
|
bool snap;
|
|
|
|
aInvalidRegion->Or(*aInvalidRegion, GetBounds(aBuilder, &snap));
|
|
|
|
}
|
2013-06-26 20:43:26 +04:00
|
|
|
|
|
|
|
nsDisplayItem::ComputeInvalidationRegion(aBuilder, aGeometry, aInvalidRegion);
|
|
|
|
}
|
|
|
|
|
2006-01-26 05:29:17 +03:00
|
|
|
void nsDisplayMathMLCharBackground::Paint(nsDisplayListBuilder* aBuilder,
|
2011-04-08 05:04:40 +04:00
|
|
|
nsRenderingContext* aCtx)
|
2006-01-26 05:29:17 +03:00
|
|
|
{
|
2013-02-17 01:51:02 +04:00
|
|
|
const nsStyleBorder* border = mStyleContext->StyleBorder();
|
2010-08-13 14:01:58 +04:00
|
|
|
nsRect rect(mRect + ToReferenceFrame());
|
2016-05-19 10:43:20 +03:00
|
|
|
nsCSSRendering::PaintBGParams params =
|
|
|
|
nsCSSRendering::PaintBGParams::ForAllLayers(*mFrame->PresContext(), *aCtx,
|
|
|
|
mVisibleRect, rect, mFrame,
|
|
|
|
aBuilder->GetBackgroundPaintFlags());
|
2015-02-10 10:27:40 +03:00
|
|
|
DrawResult result =
|
2016-05-19 10:43:20 +03:00
|
|
|
nsCSSRendering::PaintBackgroundWithSC(params, mStyleContext, *border);
|
2015-02-10 10:27:40 +03:00
|
|
|
|
|
|
|
nsDisplayItemGenericImageGeometry::UpdateDrawResult(this, result);
|
2006-01-26 05:29:17 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
class nsDisplayMathMLCharForeground : public nsDisplayItem {
|
|
|
|
public:
|
2010-08-13 14:01:13 +04:00
|
|
|
nsDisplayMathMLCharForeground(nsDisplayListBuilder* aBuilder,
|
|
|
|
nsIFrame* aFrame, nsMathMLChar* aChar,
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t aIndex, bool aIsSelected)
|
2012-04-27 04:24:54 +04:00
|
|
|
: nsDisplayItem(aBuilder, aFrame), mChar(aChar),
|
|
|
|
mIndex(aIndex), mIsSelected(aIsSelected) {
|
2006-01-29 21:48:58 +03:00
|
|
|
MOZ_COUNT_CTOR(nsDisplayMathMLCharForeground);
|
|
|
|
}
|
|
|
|
#ifdef NS_BUILD_REFCNT_LOGGING
|
|
|
|
virtual ~nsDisplayMathMLCharForeground() {
|
|
|
|
MOZ_COUNT_DTOR(nsDisplayMathMLCharForeground);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual nsRect GetBounds(nsDisplayListBuilder* aBuilder, bool* aSnap) override {
|
2012-04-10 15:24:18 +04:00
|
|
|
*aSnap = false;
|
2007-12-29 01:16:07 +03:00
|
|
|
nsRect rect;
|
|
|
|
mChar->GetRect(rect);
|
2010-08-13 14:01:58 +04:00
|
|
|
nsPoint offset = ToReferenceFrame() + rect.TopLeft();
|
2007-12-29 01:16:07 +03:00
|
|
|
nsBoundingMetrics bm;
|
|
|
|
mChar->GetBoundingMetrics(bm);
|
2012-08-29 09:39:01 +04:00
|
|
|
nsRect temp(offset.x + bm.leftBearing, offset.y,
|
|
|
|
bm.rightBearing - bm.leftBearing, bm.ascent + bm.descent);
|
|
|
|
// Bug 748220
|
|
|
|
temp.Inflate(mFrame->PresContext()->AppUnitsPerDevPixel());
|
|
|
|
return temp;
|
2007-12-29 01:16:07 +03:00
|
|
|
}
|
2012-08-29 09:39:01 +04:00
|
|
|
|
2009-09-07 04:35:14 +04:00
|
|
|
virtual void Paint(nsDisplayListBuilder* aBuilder,
|
2015-03-21 19:28:04 +03:00
|
|
|
nsRenderingContext* aCtx) override
|
2007-12-29 01:16:07 +03:00
|
|
|
{
|
|
|
|
mChar->PaintForeground(mFrame->PresContext(), *aCtx,
|
2010-08-13 14:01:58 +04:00
|
|
|
ToReferenceFrame(), mIsSelected);
|
2007-12-29 01:16:07 +03:00
|
|
|
}
|
|
|
|
|
2010-07-16 01:07:49 +04:00
|
|
|
NS_DISPLAY_DECL_NAME("MathMLCharForeground", TYPE_MATHML_CHAR_FOREGROUND)
|
2007-12-29 01:16:07 +03:00
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual nsRect GetComponentAlphaBounds(nsDisplayListBuilder* aBuilder) override
|
2011-01-03 04:48:09 +03:00
|
|
|
{
|
2012-04-10 15:24:18 +04:00
|
|
|
bool snap;
|
|
|
|
return GetBounds(aBuilder, &snap);
|
2011-01-03 04:48:09 +03:00
|
|
|
}
|
2012-04-27 04:24:54 +04:00
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual uint32_t GetPerFrameKey() override {
|
2012-08-10 19:29:59 +04:00
|
|
|
return (mIndex << nsDisplayItem::TYPE_BITS)
|
|
|
|
| nsDisplayItem::GetPerFrameKey();
|
|
|
|
}
|
2010-10-11 04:58:20 +04:00
|
|
|
|
2006-01-26 05:29:17 +03:00
|
|
|
private:
|
|
|
|
nsMathMLChar* mChar;
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t mIndex;
|
2011-09-29 10:19:26 +04:00
|
|
|
bool mIsSelected;
|
2006-01-26 05:29:17 +03:00
|
|
|
};
|
|
|
|
|
2012-06-25 23:59:42 +04:00
|
|
|
#ifdef DEBUG
|
2006-01-26 05:29:17 +03:00
|
|
|
class nsDisplayMathMLCharDebug : public nsDisplayItem {
|
|
|
|
public:
|
2010-08-13 14:01:13 +04:00
|
|
|
nsDisplayMathMLCharDebug(nsDisplayListBuilder* aBuilder,
|
|
|
|
nsIFrame* aFrame, const nsRect& aRect)
|
|
|
|
: nsDisplayItem(aBuilder, aFrame), mRect(aRect) {
|
2006-01-29 21:48:58 +03:00
|
|
|
MOZ_COUNT_CTOR(nsDisplayMathMLCharDebug);
|
|
|
|
}
|
|
|
|
#ifdef NS_BUILD_REFCNT_LOGGING
|
|
|
|
virtual ~nsDisplayMathMLCharDebug() {
|
|
|
|
MOZ_COUNT_DTOR(nsDisplayMathMLCharDebug);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2009-09-07 04:35:14 +04:00
|
|
|
virtual void Paint(nsDisplayListBuilder* aBuilder,
|
2015-03-21 19:28:04 +03:00
|
|
|
nsRenderingContext* aCtx) override;
|
2010-07-16 01:07:49 +04:00
|
|
|
NS_DISPLAY_DECL_NAME("MathMLCharDebug", TYPE_MATHML_CHAR_DEBUG)
|
2010-08-13 14:01:13 +04:00
|
|
|
|
2006-01-26 05:29:17 +03:00
|
|
|
private:
|
2010-08-13 14:01:13 +04:00
|
|
|
nsRect mRect;
|
2006-01-26 05:29:17 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
void nsDisplayMathMLCharDebug::Paint(nsDisplayListBuilder* aBuilder,
|
2011-04-08 05:04:40 +04:00
|
|
|
nsRenderingContext* aCtx)
|
2006-01-26 05:29:17 +03:00
|
|
|
{
|
|
|
|
// for visual debug
|
2014-06-28 14:13:13 +04:00
|
|
|
Sides skipSides;
|
2007-03-31 01:11:41 +04:00
|
|
|
nsPresContext* presContext = mFrame->PresContext();
|
2013-02-16 09:38:33 +04:00
|
|
|
nsStyleContext* styleContext = mFrame->StyleContext();
|
2010-08-13 14:01:58 +04:00
|
|
|
nsRect rect = mRect + ToReferenceFrame();
|
2015-10-23 05:54:49 +03:00
|
|
|
|
|
|
|
PaintBorderFlags flags = aBuilder->ShouldSyncDecodeImages()
|
|
|
|
? PaintBorderFlags::SYNC_DECODE_IMAGES
|
|
|
|
: PaintBorderFlags();
|
|
|
|
|
|
|
|
// Since this is used only for debugging, we don't need to worry about
|
|
|
|
// tracking the DrawResult.
|
2015-11-02 08:53:26 +03:00
|
|
|
Unused <<
|
2015-10-23 05:54:49 +03:00
|
|
|
nsCSSRendering::PaintBorder(presContext, *aCtx, mFrame, mVisibleRect,
|
|
|
|
rect, styleContext, flags, skipSides);
|
|
|
|
|
2006-01-26 05:29:17 +03:00
|
|
|
nsCSSRendering::PaintOutline(presContext, *aCtx, mFrame,
|
2010-04-03 05:58:26 +04:00
|
|
|
mVisibleRect, rect, styleContext);
|
2006-01-26 05:29:17 +03:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2013-02-14 15:12:27 +04:00
|
|
|
void
|
2006-01-26 05:29:17 +03:00
|
|
|
nsMathMLChar::Display(nsDisplayListBuilder* aBuilder,
|
|
|
|
nsIFrame* aForFrame,
|
|
|
|
const nsDisplayListSet& aLists,
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t aIndex,
|
2006-01-26 05:29:17 +03:00
|
|
|
const nsRect* aSelectedRect)
|
1999-09-21 06:12:01 +04:00
|
|
|
{
|
2003-02-22 03:32:13 +03:00
|
|
|
nsStyleContext* parentContext = mStyleContext->GetParent();
|
|
|
|
nsStyleContext* styleContext = mStyleContext;
|
2001-02-02 12:40:53 +03:00
|
|
|
|
2014-02-13 18:53:52 +04:00
|
|
|
if (mDraw == DRAW_NORMAL) {
|
2001-02-02 12:40:53 +03:00
|
|
|
// normal drawing if there is nothing special about this char
|
2001-02-23 19:10:51 +03:00
|
|
|
// Set default context to the parent context
|
|
|
|
styleContext = parentContext;
|
2001-02-02 12:40:53 +03:00
|
|
|
}
|
|
|
|
|
2013-02-17 01:51:02 +04:00
|
|
|
if (!styleContext->StyleVisibility()->IsVisible())
|
2013-02-14 15:12:27 +04:00
|
|
|
return;
|
2000-03-28 13:38:24 +04:00
|
|
|
|
2002-02-27 04:35:27 +03:00
|
|
|
// if the leaf style context that we use for stretchy chars has a background
|
|
|
|
// color we use it -- this feature is mostly used for testing and debugging
|
|
|
|
// purposes. Normally, users will set the background on the container frame.
|
2006-01-26 05:29:17 +03:00
|
|
|
// paint the selection background -- beware MathML frames overlap a lot
|
|
|
|
if (aSelectedRect && !aSelectedRect->IsEmpty()) {
|
2013-02-14 15:08:08 +04:00
|
|
|
aLists.BorderBackground()->AppendNewToTop(new (aBuilder)
|
|
|
|
nsDisplayMathMLSelectionRect(aBuilder, aForFrame, *aSelectedRect));
|
2006-01-26 05:29:17 +03:00
|
|
|
}
|
|
|
|
else if (mRect.width && mRect.height) {
|
2013-02-17 01:51:02 +04:00
|
|
|
const nsStyleBackground* backg = styleContext->StyleBackground();
|
2006-01-26 05:29:17 +03:00
|
|
|
if (styleContext != parentContext &&
|
2008-09-12 19:35:53 +04:00
|
|
|
NS_GET_A(backg->mBackgroundColor) > 0) {
|
2013-02-14 15:08:08 +04:00
|
|
|
aLists.BorderBackground()->AppendNewToTop(new (aBuilder)
|
|
|
|
nsDisplayMathMLCharBackground(aBuilder, aForFrame, mRect,
|
|
|
|
styleContext));
|
2002-04-02 08:15:22 +04:00
|
|
|
}
|
2006-01-26 05:29:17 +03:00
|
|
|
//else
|
|
|
|
// our container frame will take care of painting its background
|
|
|
|
|
2012-06-25 23:59:42 +04:00
|
|
|
#if defined(DEBUG) && defined(SHOW_BOUNDING_BOX)
|
2006-01-26 05:29:17 +03:00
|
|
|
// for visual debug
|
2013-02-14 15:08:08 +04:00
|
|
|
aLists.BorderBackground()->AppendToTop(new (aBuilder)
|
|
|
|
nsDisplayMathMLCharDebug(aBuilder, aForFrame, mRect));
|
2002-02-27 04:35:27 +03:00
|
|
|
#endif
|
2000-03-28 13:38:24 +04:00
|
|
|
}
|
2013-02-14 15:08:08 +04:00
|
|
|
aLists.Content()->AppendNewToTop(new (aBuilder)
|
|
|
|
nsDisplayMathMLCharForeground(aBuilder, aForFrame, this,
|
|
|
|
aIndex,
|
|
|
|
aSelectedRect &&
|
|
|
|
!aSelectedRect->IsEmpty()));
|
2006-01-26 05:29:17 +03:00
|
|
|
}
|
1999-09-21 06:12:01 +04:00
|
|
|
|
2010-08-20 07:44:07 +04:00
|
|
|
void
|
2014-02-13 18:53:52 +04:00
|
|
|
nsMathMLChar::ApplyTransforms(gfxContext* aThebesContext,
|
|
|
|
int32_t aAppUnitsPerGfxUnit,
|
|
|
|
nsRect &r)
|
2010-08-20 07:44:07 +04:00
|
|
|
{
|
|
|
|
// apply the transforms
|
2011-12-22 02:22:00 +04:00
|
|
|
if (mMirrored) {
|
2014-02-13 18:53:52 +04:00
|
|
|
nsPoint pt = r.TopRight();
|
2014-09-11 10:57:38 +04:00
|
|
|
gfxPoint devPixelOffset(NSAppUnitsToFloatPixels(pt.x, aAppUnitsPerGfxUnit),
|
|
|
|
NSAppUnitsToFloatPixels(pt.y, aAppUnitsPerGfxUnit));
|
|
|
|
aThebesContext->SetMatrix(
|
|
|
|
aThebesContext->CurrentMatrix().Translate(devPixelOffset).
|
|
|
|
Scale(-mScaleX, mScaleY));
|
2011-12-22 02:22:00 +04:00
|
|
|
} else {
|
2014-02-13 18:53:52 +04:00
|
|
|
nsPoint pt = r.TopLeft();
|
2014-09-11 10:57:38 +04:00
|
|
|
gfxPoint devPixelOffset(NSAppUnitsToFloatPixels(pt.x, aAppUnitsPerGfxUnit),
|
|
|
|
NSAppUnitsToFloatPixels(pt.y, aAppUnitsPerGfxUnit));
|
|
|
|
aThebesContext->SetMatrix(
|
|
|
|
aThebesContext->CurrentMatrix().Translate(devPixelOffset).
|
|
|
|
Scale(mScaleX, mScaleY));
|
2011-12-22 02:22:00 +04:00
|
|
|
}
|
2010-08-20 07:44:07 +04:00
|
|
|
|
|
|
|
// update the bounding rectangle.
|
|
|
|
r.x = r.y = 0;
|
|
|
|
r.width /= mScaleX;
|
|
|
|
r.height /= mScaleY;
|
|
|
|
}
|
|
|
|
|
2006-01-26 05:29:17 +03:00
|
|
|
void
|
|
|
|
nsMathMLChar::PaintForeground(nsPresContext* aPresContext,
|
2011-04-08 05:04:40 +04:00
|
|
|
nsRenderingContext& aRenderingContext,
|
2006-01-26 05:29:17 +03:00
|
|
|
nsPoint aPt,
|
2011-09-29 10:19:26 +04:00
|
|
|
bool aIsSelected)
|
2006-01-26 05:29:17 +03:00
|
|
|
{
|
|
|
|
nsStyleContext* parentContext = mStyleContext->GetParent();
|
|
|
|
nsStyleContext* styleContext = mStyleContext;
|
2000-04-17 08:19:54 +04:00
|
|
|
|
2014-02-13 18:53:52 +04:00
|
|
|
if (mDraw == DRAW_NORMAL) {
|
2006-01-26 05:29:17 +03:00
|
|
|
// normal drawing if there is nothing special about this char
|
|
|
|
// Set default context to the parent context
|
|
|
|
styleContext = parentContext;
|
|
|
|
}
|
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<gfxContext> thebesContext = aRenderingContext.ThebesContext();
|
2014-02-13 18:53:52 +04:00
|
|
|
|
2006-01-26 05:29:17 +03:00
|
|
|
// Set color ...
|
2016-08-10 02:28:19 +03:00
|
|
|
nsCSSPropertyID colorProp = styleContext->GetTextFillColorProp();
|
2016-04-19 12:10:06 +03:00
|
|
|
nscolor fgColor = styleContext->GetVisitedDependentColor(colorProp);
|
2006-01-26 05:29:17 +03:00
|
|
|
if (aIsSelected) {
|
|
|
|
// get color to use for selection from the look&feel object
|
2011-09-09 06:27:13 +04:00
|
|
|
fgColor = LookAndFeel::GetColor(LookAndFeel::eColorID_TextSelectForeground,
|
|
|
|
fgColor);
|
2006-01-26 05:29:17 +03:00
|
|
|
}
|
2015-09-24 09:41:30 +03:00
|
|
|
thebesContext->SetColor(Color::FromABGR(fgColor));
|
2014-02-13 18:53:52 +04:00
|
|
|
thebesContext->Save();
|
2010-08-20 07:44:07 +04:00
|
|
|
nsRect r = mRect + aPt;
|
2014-02-13 18:53:52 +04:00
|
|
|
ApplyTransforms(thebesContext, aPresContext->AppUnitsPerDevPixel(), r);
|
2010-08-20 07:44:07 +04:00
|
|
|
|
2014-02-13 18:53:52 +04:00
|
|
|
switch(mDraw)
|
|
|
|
{
|
|
|
|
case DRAW_NORMAL:
|
|
|
|
case DRAW_VARIANT:
|
|
|
|
// draw a single glyph (base size or size variant)
|
2014-02-20 17:43:56 +04:00
|
|
|
// XXXfredw verify if mGlyphs[0] is non-null to workaround bug 973322.
|
|
|
|
if (mGlyphs[0]) {
|
2016-04-19 19:13:28 +03:00
|
|
|
mGlyphs[0]->Draw(Range(mGlyphs[0].get()), gfxPoint(0.0, mUnscaledAscent),
|
2016-03-08 10:56:18 +03:00
|
|
|
gfxTextRun::DrawParams(thebesContext));
|
2014-02-20 17:43:56 +04:00
|
|
|
}
|
2014-02-13 18:53:52 +04:00
|
|
|
break;
|
|
|
|
case DRAW_PARTS: {
|
|
|
|
// paint by parts
|
2006-01-26 05:29:17 +03:00
|
|
|
if (NS_STRETCH_DIRECTION_VERTICAL == mDirection)
|
2014-11-24 03:04:33 +03:00
|
|
|
PaintVertically(aPresContext, thebesContext, r, fgColor);
|
2006-01-26 05:29:17 +03:00
|
|
|
else if (NS_STRETCH_DIRECTION_HORIZONTAL == mDirection)
|
2014-11-24 03:04:33 +03:00
|
|
|
PaintHorizontally(aPresContext, thebesContext, r, fgColor);
|
2014-02-13 18:53:52 +04:00
|
|
|
break;
|
2000-03-28 13:38:24 +04:00
|
|
|
}
|
2014-02-13 18:53:52 +04:00
|
|
|
default:
|
|
|
|
NS_NOTREACHED("Unknown drawing method");
|
|
|
|
break;
|
1999-11-22 01:10:45 +03:00
|
|
|
}
|
2010-08-20 07:44:07 +04:00
|
|
|
|
2014-02-13 18:53:52 +04:00
|
|
|
thebesContext->Restore();
|
1999-11-22 01:10:45 +03:00
|
|
|
}
|
1999-11-17 03:49:37 +03:00
|
|
|
|
2012-08-10 19:29:59 +04:00
|
|
|
/* =============================================================================
|
|
|
|
Helper routines that actually do the job of painting the char by parts
|
1999-11-22 01:10:45 +03:00
|
|
|
*/
|
1999-11-17 03:49:37 +03:00
|
|
|
|
2007-12-05 06:58:09 +03:00
|
|
|
class AutoPushClipRect {
|
2014-02-13 18:53:52 +04:00
|
|
|
gfxContext* mThebesContext;
|
2007-12-05 06:58:09 +03:00
|
|
|
public:
|
2014-02-13 18:53:52 +04:00
|
|
|
AutoPushClipRect(gfxContext* aThebesContext, int32_t aAppUnitsPerGfxUnit,
|
|
|
|
const nsRect& aRect)
|
|
|
|
: mThebesContext(aThebesContext) {
|
|
|
|
mThebesContext->Save();
|
|
|
|
mThebesContext->NewPath();
|
|
|
|
gfxRect clip = nsLayoutUtils::RectToGfxRect(aRect, aAppUnitsPerGfxUnit);
|
|
|
|
mThebesContext->SnappedRectangle(clip);
|
|
|
|
mThebesContext->Clip();
|
2007-12-05 06:58:09 +03:00
|
|
|
}
|
|
|
|
~AutoPushClipRect() {
|
2014-02-13 18:53:52 +04:00
|
|
|
mThebesContext->Restore();
|
2007-12-05 06:58:09 +03:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2008-04-23 07:13:09 +04:00
|
|
|
static nsPoint
|
2012-08-22 19:56:38 +04:00
|
|
|
SnapToDevPixels(const gfxContext* aThebesContext, int32_t aAppUnitsPerGfxUnit,
|
2008-04-23 07:13:09 +04:00
|
|
|
const nsPoint& aPt)
|
|
|
|
{
|
|
|
|
gfxPoint pt(NSAppUnitsToFloatPixels(aPt.x, aAppUnitsPerGfxUnit),
|
|
|
|
NSAppUnitsToFloatPixels(aPt.y, aAppUnitsPerGfxUnit));
|
|
|
|
pt = aThebesContext->UserToDevice(pt);
|
|
|
|
pt.Round();
|
|
|
|
pt = aThebesContext->DeviceToUser(pt);
|
|
|
|
return nsPoint(NSFloatPixelsToAppUnits(pt.x, aAppUnitsPerGfxUnit),
|
|
|
|
NSFloatPixelsToAppUnits(pt.y, aAppUnitsPerGfxUnit));
|
|
|
|
}
|
|
|
|
|
2014-02-13 18:53:52 +04:00
|
|
|
static void
|
2014-11-24 03:04:33 +03:00
|
|
|
PaintRule(DrawTarget& aDrawTarget,
|
2014-02-13 18:53:52 +04:00
|
|
|
int32_t aAppUnitsPerGfxUnit,
|
2014-11-24 03:04:33 +03:00
|
|
|
nsRect& aRect,
|
|
|
|
nscolor aColor)
|
2014-02-13 18:53:52 +04:00
|
|
|
{
|
2014-11-24 03:04:33 +03:00
|
|
|
Rect rect = NSRectToSnappedRect(aRect, aAppUnitsPerGfxUnit, aDrawTarget);
|
|
|
|
ColorPattern color(ToDeviceColor(aColor));
|
|
|
|
aDrawTarget.FillRect(rect, color);
|
2014-02-13 18:53:52 +04:00
|
|
|
}
|
|
|
|
|
1999-11-22 01:10:45 +03:00
|
|
|
// paint a stretchy char by assembling glyphs vertically
|
|
|
|
nsresult
|
2014-02-13 18:53:52 +04:00
|
|
|
nsMathMLChar::PaintVertically(nsPresContext* aPresContext,
|
|
|
|
gfxContext* aThebesContext,
|
2014-11-24 03:04:33 +03:00
|
|
|
nsRect& aRect,
|
|
|
|
nscolor aColor)
|
1999-11-22 01:10:45 +03:00
|
|
|
{
|
2014-11-24 03:04:33 +03:00
|
|
|
DrawTarget& aDrawTarget = *aThebesContext->GetDrawTarget();
|
|
|
|
|
2008-04-23 07:13:09 +04:00
|
|
|
// Get the device pixel size in the vertical direction.
|
|
|
|
// (This makes no effort to optimize for non-translation transformations.)
|
|
|
|
nscoord oneDevPixel = aPresContext->AppUnitsPerDevPixel();
|
1999-11-22 01:10:45 +03:00
|
|
|
|
|
|
|
// get metrics data to be re-used later
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t i = 0;
|
2008-04-23 07:13:09 +04:00
|
|
|
nscoord dx = aRect.x;
|
|
|
|
nscoord offset[3], start[3], end[3];
|
2014-02-13 18:53:52 +04:00
|
|
|
for (i = 0; i <= 2; ++i) {
|
|
|
|
const nsBoundingMetrics& bm = mBmData[i];
|
2008-04-23 07:13:09 +04:00
|
|
|
nscoord dy;
|
1999-11-22 01:10:45 +03:00
|
|
|
if (0 == i) { // top
|
2001-10-31 01:58:00 +03:00
|
|
|
dy = aRect.y + bm.ascent;
|
1999-11-17 03:49:37 +03:00
|
|
|
}
|
2014-02-13 18:53:52 +04:00
|
|
|
else if (2 == i) { // bottom
|
2001-10-31 01:58:00 +03:00
|
|
|
dy = aRect.y + aRect.height - bm.descent;
|
1999-11-22 01:10:45 +03:00
|
|
|
}
|
2008-04-23 07:13:09 +04:00
|
|
|
else { // middle
|
|
|
|
dy = aRect.y + bm.ascent + (aRect.height - (bm.ascent + bm.descent))/2;
|
|
|
|
}
|
|
|
|
// _cairo_scaled_font_show_glyphs snaps origins to device pixels.
|
|
|
|
// Do this now so that we can get the other dimensions right.
|
|
|
|
// (This may not achieve much with non-rectangular transformations.)
|
2014-02-13 18:53:52 +04:00
|
|
|
dy = SnapToDevPixels(aThebesContext, oneDevPixel, nsPoint(dx, dy)).y;
|
|
|
|
// abcissa passed to Draw
|
1999-11-22 01:10:45 +03:00
|
|
|
offset[i] = dy;
|
2008-04-23 07:13:09 +04:00
|
|
|
// _cairo_scaled_font_glyph_device_extents rounds outwards to the nearest
|
|
|
|
// pixel, so the bm values can include 1 row of faint pixels on each edge.
|
|
|
|
// Don't rely on this pixel as it can look like a gap.
|
2014-02-13 18:53:52 +04:00
|
|
|
if (bm.ascent + bm.descent >= 2 * oneDevPixel) {
|
|
|
|
start[i] = dy - bm.ascent + oneDevPixel; // top join
|
|
|
|
end[i] = dy + bm.descent - oneDevPixel; // bottom join
|
|
|
|
} else {
|
|
|
|
// To avoid overlaps, we don't add one pixel on each side when the part
|
|
|
|
// is too small.
|
|
|
|
start[i] = dy - bm.ascent; // top join
|
|
|
|
end[i] = dy + bm.descent; // bottom join
|
|
|
|
}
|
2008-04-23 07:13:09 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// If there are overlaps, then join at the mid point
|
2014-02-13 18:53:52 +04:00
|
|
|
for (i = 0; i < 2; ++i) {
|
2008-04-23 07:13:09 +04:00
|
|
|
if (end[i] > start[i+1]) {
|
|
|
|
end[i] = (end[i] + start[i+1]) / 2;
|
|
|
|
start[i+1] = end[i];
|
|
|
|
}
|
1999-11-22 01:10:45 +03:00
|
|
|
}
|
1999-09-21 06:12:01 +04:00
|
|
|
|
2008-04-23 07:13:09 +04:00
|
|
|
nsRect unionRect = aRect;
|
|
|
|
unionRect.x += mBoundingMetrics.leftBearing;
|
|
|
|
unionRect.width =
|
|
|
|
mBoundingMetrics.rightBearing - mBoundingMetrics.leftBearing;
|
|
|
|
unionRect.Inflate(oneDevPixel, oneDevPixel);
|
|
|
|
|
2016-03-08 10:56:18 +03:00
|
|
|
gfxTextRun::DrawParams params(aThebesContext);
|
|
|
|
|
1999-11-22 01:10:45 +03:00
|
|
|
/////////////////////////////////////
|
|
|
|
// draw top, middle, bottom
|
2014-02-13 18:53:52 +04:00
|
|
|
for (i = 0; i <= 2; ++i) {
|
|
|
|
// glue can be null
|
|
|
|
if (mGlyphs[i]) {
|
2008-04-23 07:13:09 +04:00
|
|
|
nscoord dy = offset[i];
|
|
|
|
// Draw a glyph in a clipped area so that we don't have hairy chars
|
|
|
|
// pending outside
|
|
|
|
nsRect clipRect = unionRect;
|
|
|
|
// Clip at the join to get a solid edge (without overlap or gap), when
|
|
|
|
// this won't change the glyph too much. If the glyph is too small to
|
|
|
|
// clip then we'll overlap rather than have a gap.
|
2014-02-13 18:53:52 +04:00
|
|
|
nscoord height = mBmData[i].ascent + mBmData[i].descent;
|
|
|
|
if (height * (1.0 - NS_MATHML_DELIMITER_FACTOR) > oneDevPixel) {
|
2008-04-23 07:13:09 +04:00
|
|
|
if (0 == i) { // top
|
|
|
|
clipRect.height = end[i] - clipRect.y;
|
|
|
|
}
|
2014-02-13 18:53:52 +04:00
|
|
|
else if (2 == i) { // bottom
|
2008-04-23 07:13:09 +04:00
|
|
|
clipRect.height -= start[i] - clipRect.y;
|
|
|
|
clipRect.y = start[i];
|
|
|
|
}
|
|
|
|
else { // middle
|
|
|
|
clipRect.y = start[i];
|
|
|
|
clipRect.height = end[i] - start[i];
|
|
|
|
}
|
2001-02-02 12:40:53 +03:00
|
|
|
}
|
|
|
|
if (!clipRect.IsEmpty()) {
|
2014-02-13 18:53:52 +04:00
|
|
|
AutoPushClipRect clip(aThebesContext, oneDevPixel, clipRect);
|
2016-04-19 19:13:28 +03:00
|
|
|
mGlyphs[i]->Draw(Range(mGlyphs[i].get()), gfxPoint(dx, dy), params);
|
2001-02-02 12:40:53 +03:00
|
|
|
}
|
1999-11-22 01:10:45 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
///////////////
|
|
|
|
// fill the gap between top and middle, and between middle and bottom.
|
2014-02-13 18:53:52 +04:00
|
|
|
if (!mGlyphs[3]) { // null glue : draw a rule
|
2001-02-02 12:40:53 +03:00
|
|
|
// figure out the dimensions of the rule to be drawn :
|
2012-08-10 19:29:59 +04:00
|
|
|
// set lbearing to rightmost lbearing among the two current successive
|
|
|
|
// parts.
|
2001-02-02 12:40:53 +03:00
|
|
|
// set rbearing to leftmost rbearing among the two current successive parts.
|
|
|
|
// this not only satisfies the convention used for over/underbraces
|
|
|
|
// in TeX, but also takes care of broken fonts like the stretchy integral
|
|
|
|
// in Symbol for small font sizes in unix.
|
|
|
|
nscoord lbearing, rbearing;
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t first = 0, last = 1;
|
2014-02-13 18:53:52 +04:00
|
|
|
while (last <= 2) {
|
|
|
|
if (mGlyphs[last]) {
|
|
|
|
lbearing = mBmData[last].leftBearing;
|
|
|
|
rbearing = mBmData[last].rightBearing;
|
|
|
|
if (mGlyphs[first]) {
|
|
|
|
if (lbearing < mBmData[first].leftBearing)
|
|
|
|
lbearing = mBmData[first].leftBearing;
|
|
|
|
if (rbearing > mBmData[first].rightBearing)
|
|
|
|
rbearing = mBmData[first].rightBearing;
|
2001-02-02 12:40:53 +03:00
|
|
|
}
|
|
|
|
}
|
2014-02-13 18:53:52 +04:00
|
|
|
else if (mGlyphs[first]) {
|
|
|
|
lbearing = mBmData[first].leftBearing;
|
|
|
|
rbearing = mBmData[first].rightBearing;
|
2001-02-02 12:40:53 +03:00
|
|
|
}
|
|
|
|
else {
|
2002-02-27 04:35:27 +03:00
|
|
|
NS_ERROR("Cannot stretch - All parts missing");
|
2001-02-02 12:40:53 +03:00
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
}
|
|
|
|
// paint the rule between the parts
|
2008-04-23 07:13:09 +04:00
|
|
|
nsRect rule(aRect.x + lbearing, end[first],
|
|
|
|
rbearing - lbearing, start[last] - end[first]);
|
2014-11-24 03:04:33 +03:00
|
|
|
PaintRule(aDrawTarget, oneDevPixel, rule, aColor);
|
2001-02-02 12:40:53 +03:00
|
|
|
first = last;
|
|
|
|
last++;
|
|
|
|
}
|
|
|
|
}
|
2014-02-13 18:53:52 +04:00
|
|
|
else if (mBmData[3].ascent + mBmData[3].descent > 0) {
|
2008-01-03 07:21:36 +03:00
|
|
|
// glue is present
|
2014-02-13 18:53:52 +04:00
|
|
|
nsBoundingMetrics& bm = mBmData[3];
|
2008-04-23 07:13:09 +04:00
|
|
|
// Ensure the stride for the glue is not reduced to less than one pixel
|
|
|
|
if (bm.ascent + bm.descent >= 3 * oneDevPixel) {
|
|
|
|
// To protect against gaps, pretend the glue is smaller than it is,
|
|
|
|
// in order to trim off ends and thus get a solid edge for the join.
|
|
|
|
bm.ascent -= oneDevPixel;
|
|
|
|
bm.descent -= oneDevPixel;
|
2006-10-06 19:38:17 +04:00
|
|
|
}
|
2008-04-23 07:13:09 +04:00
|
|
|
|
|
|
|
nsRect clipRect = unionRect;
|
|
|
|
|
2014-02-13 18:53:52 +04:00
|
|
|
for (i = 0; i < 2; ++i) {
|
2008-04-23 07:13:09 +04:00
|
|
|
// Make sure not to draw outside the character
|
2013-01-15 16:22:03 +04:00
|
|
|
nscoord dy = std::max(end[i], aRect.y);
|
|
|
|
nscoord fillEnd = std::min(start[i+1], aRect.YMost());
|
2008-04-23 07:13:09 +04:00
|
|
|
while (dy < fillEnd) {
|
|
|
|
clipRect.y = dy;
|
2013-01-15 16:22:03 +04:00
|
|
|
clipRect.height = std::min(bm.ascent + bm.descent, fillEnd - dy);
|
2014-02-13 18:53:52 +04:00
|
|
|
AutoPushClipRect clip(aThebesContext, oneDevPixel, clipRect);
|
2008-04-23 07:13:09 +04:00
|
|
|
dy += bm.ascent;
|
2016-04-19 19:13:28 +03:00
|
|
|
mGlyphs[3]->Draw(Range(mGlyphs[3].get()), gfxPoint(dx, dy), params);
|
2008-04-23 07:13:09 +04:00
|
|
|
dy += bm.descent;
|
1999-11-17 03:49:37 +03:00
|
|
|
}
|
2001-02-02 12:40:53 +03:00
|
|
|
}
|
1999-11-22 01:10:45 +03:00
|
|
|
}
|
2008-01-03 07:21:36 +03:00
|
|
|
#ifdef DEBUG
|
2008-04-23 07:13:09 +04:00
|
|
|
else {
|
2014-02-13 18:53:52 +04:00
|
|
|
for (i = 0; i < 2; ++i) {
|
2008-04-23 07:13:09 +04:00
|
|
|
NS_ASSERTION(end[i] >= start[i+1],
|
|
|
|
"gap between parts with missing glue glyph");
|
|
|
|
}
|
2008-01-03 07:21:36 +03:00
|
|
|
}
|
|
|
|
#endif
|
2000-03-28 13:38:24 +04:00
|
|
|
return NS_OK;
|
1999-11-22 01:10:45 +03:00
|
|
|
}
|
1999-11-17 03:49:37 +03:00
|
|
|
|
1999-11-22 01:10:45 +03:00
|
|
|
// paint a stretchy char by assembling glyphs horizontally
|
|
|
|
nsresult
|
2014-02-13 18:53:52 +04:00
|
|
|
nsMathMLChar::PaintHorizontally(nsPresContext* aPresContext,
|
|
|
|
gfxContext* aThebesContext,
|
2014-11-24 03:04:33 +03:00
|
|
|
nsRect& aRect,
|
|
|
|
nscolor aColor)
|
1999-11-22 01:10:45 +03:00
|
|
|
{
|
2014-11-24 03:04:33 +03:00
|
|
|
DrawTarget& aDrawTarget = *aThebesContext->GetDrawTarget();
|
|
|
|
|
2008-04-23 07:13:09 +04:00
|
|
|
// Get the device pixel size in the horizontal direction.
|
|
|
|
// (This makes no effort to optimize for non-translation transformations.)
|
|
|
|
nscoord oneDevPixel = aPresContext->AppUnitsPerDevPixel();
|
1999-11-22 01:10:45 +03:00
|
|
|
|
|
|
|
// get metrics data to be re-used later
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t i = 0;
|
2008-04-23 07:13:09 +04:00
|
|
|
nscoord dy = aRect.y + mBoundingMetrics.ascent;
|
|
|
|
nscoord offset[3], start[3], end[3];
|
2014-02-13 18:53:52 +04:00
|
|
|
for (i = 0; i <= 2; ++i) {
|
|
|
|
const nsBoundingMetrics& bm = mBmData[i];
|
2008-04-23 07:13:09 +04:00
|
|
|
nscoord dx;
|
2000-03-28 13:38:24 +04:00
|
|
|
if (0 == i) { // left
|
1999-11-22 01:10:45 +03:00
|
|
|
dx = aRect.x - bm.leftBearing;
|
|
|
|
}
|
2014-02-13 18:53:52 +04:00
|
|
|
else if (2 == i) { // right
|
1999-11-22 01:10:45 +03:00
|
|
|
dx = aRect.x + aRect.width - bm.rightBearing;
|
1999-11-17 03:49:37 +03:00
|
|
|
}
|
2008-04-23 07:13:09 +04:00
|
|
|
else { // middle
|
|
|
|
dx = aRect.x + (aRect.width - bm.width)/2;
|
|
|
|
}
|
|
|
|
// _cairo_scaled_font_show_glyphs snaps origins to device pixels.
|
|
|
|
// Do this now so that we can get the other dimensions right.
|
|
|
|
// (This may not achieve much with non-rectangular transformations.)
|
2014-02-13 18:53:52 +04:00
|
|
|
dx = SnapToDevPixels(aThebesContext, oneDevPixel, nsPoint(dx, dy)).x;
|
|
|
|
// abcissa passed to Draw
|
1999-11-22 01:10:45 +03:00
|
|
|
offset[i] = dx;
|
2008-04-23 07:13:09 +04:00
|
|
|
// _cairo_scaled_font_glyph_device_extents rounds outwards to the nearest
|
|
|
|
// pixel, so the bm values can include 1 row of faint pixels on each edge.
|
|
|
|
// Don't rely on this pixel as it can look like a gap.
|
2014-02-13 18:53:52 +04:00
|
|
|
if (bm.rightBearing - bm.leftBearing >= 2 * oneDevPixel) {
|
|
|
|
start[i] = dx + bm.leftBearing + oneDevPixel; // left join
|
|
|
|
end[i] = dx + bm.rightBearing - oneDevPixel; // right join
|
|
|
|
} else {
|
|
|
|
// To avoid overlaps, we don't add one pixel on each side when the part
|
|
|
|
// is too small.
|
|
|
|
start[i] = dx + bm.leftBearing; // left join
|
|
|
|
end[i] = dx + bm.rightBearing; // right join
|
|
|
|
}
|
2008-04-23 07:13:09 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// If there are overlaps, then join at the mid point
|
2014-02-13 18:53:52 +04:00
|
|
|
for (i = 0; i < 2; ++i) {
|
2008-04-23 07:13:09 +04:00
|
|
|
if (end[i] > start[i+1]) {
|
|
|
|
end[i] = (end[i] + start[i+1]) / 2;
|
|
|
|
start[i+1] = end[i];
|
|
|
|
}
|
1999-11-22 01:10:45 +03:00
|
|
|
}
|
1999-11-17 03:49:37 +03:00
|
|
|
|
2008-04-23 07:13:09 +04:00
|
|
|
nsRect unionRect = aRect;
|
|
|
|
unionRect.Inflate(oneDevPixel, oneDevPixel);
|
|
|
|
|
2016-03-08 10:56:18 +03:00
|
|
|
gfxTextRun::DrawParams params(aThebesContext);
|
|
|
|
|
1999-11-22 01:10:45 +03:00
|
|
|
///////////////////////////
|
|
|
|
// draw left, middle, right
|
2014-02-13 18:53:52 +04:00
|
|
|
for (i = 0; i <= 2; ++i) {
|
|
|
|
// glue can be null
|
|
|
|
if (mGlyphs[i]) {
|
2008-04-23 07:13:09 +04:00
|
|
|
nscoord dx = offset[i];
|
|
|
|
nsRect clipRect = unionRect;
|
|
|
|
// Clip at the join to get a solid edge (without overlap or gap), when
|
|
|
|
// this won't change the glyph too much. If the glyph is too small to
|
|
|
|
// clip then we'll overlap rather than have a gap.
|
2014-02-13 18:53:52 +04:00
|
|
|
nscoord width = mBmData[i].rightBearing - mBmData[i].leftBearing;
|
|
|
|
if (width * (1.0 - NS_MATHML_DELIMITER_FACTOR) > oneDevPixel) {
|
2008-04-23 07:13:09 +04:00
|
|
|
if (0 == i) { // left
|
|
|
|
clipRect.width = end[i] - clipRect.x;
|
|
|
|
}
|
2014-02-13 18:53:52 +04:00
|
|
|
else if (2 == i) { // right
|
2008-04-23 07:13:09 +04:00
|
|
|
clipRect.width -= start[i] - clipRect.x;
|
|
|
|
clipRect.x = start[i];
|
|
|
|
}
|
|
|
|
else { // middle
|
|
|
|
clipRect.x = start[i];
|
|
|
|
clipRect.width = end[i] - start[i];
|
|
|
|
}
|
2001-02-02 12:40:53 +03:00
|
|
|
}
|
|
|
|
if (!clipRect.IsEmpty()) {
|
2014-02-13 18:53:52 +04:00
|
|
|
AutoPushClipRect clip(aThebesContext, oneDevPixel, clipRect);
|
2016-04-19 19:13:28 +03:00
|
|
|
mGlyphs[i]->Draw(Range(mGlyphs[i].get()), gfxPoint(dx, dy), params);
|
2001-02-02 12:40:53 +03:00
|
|
|
}
|
1999-11-22 01:10:45 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
////////////////
|
|
|
|
// fill the gap between left and middle, and between middle and right.
|
2014-02-13 18:53:52 +04:00
|
|
|
if (!mGlyphs[3]) { // null glue : draw a rule
|
2001-02-02 12:40:53 +03:00
|
|
|
// figure out the dimensions of the rule to be drawn :
|
|
|
|
// set ascent to lowest ascent among the two current successive parts.
|
|
|
|
// set descent to highest descent among the two current successive parts.
|
|
|
|
// this satisfies the convention used for over/underbraces, and helps
|
|
|
|
// fix broken fonts.
|
|
|
|
nscoord ascent, descent;
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t first = 0, last = 1;
|
2014-02-13 18:53:52 +04:00
|
|
|
while (last <= 2) {
|
|
|
|
if (mGlyphs[last]) {
|
|
|
|
ascent = mBmData[last].ascent;
|
|
|
|
descent = mBmData[last].descent;
|
|
|
|
if (mGlyphs[first]) {
|
|
|
|
if (ascent > mBmData[first].ascent)
|
|
|
|
ascent = mBmData[first].ascent;
|
|
|
|
if (descent > mBmData[first].descent)
|
|
|
|
descent = mBmData[first].descent;
|
2001-02-02 12:40:53 +03:00
|
|
|
}
|
|
|
|
}
|
2014-02-13 18:53:52 +04:00
|
|
|
else if (mGlyphs[first]) {
|
|
|
|
ascent = mBmData[first].ascent;
|
|
|
|
descent = mBmData[first].descent;
|
2001-02-02 12:40:53 +03:00
|
|
|
}
|
|
|
|
else {
|
2002-02-27 04:35:27 +03:00
|
|
|
NS_ERROR("Cannot stretch - All parts missing");
|
2001-02-02 12:40:53 +03:00
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
}
|
|
|
|
// paint the rule between the parts
|
2008-04-23 07:13:09 +04:00
|
|
|
nsRect rule(end[first], dy - ascent,
|
|
|
|
start[last] - end[first], ascent + descent);
|
2014-11-24 03:04:33 +03:00
|
|
|
PaintRule(aDrawTarget, oneDevPixel, rule, aColor);
|
2001-02-02 12:40:53 +03:00
|
|
|
first = last;
|
|
|
|
last++;
|
|
|
|
}
|
|
|
|
}
|
2014-02-13 18:53:52 +04:00
|
|
|
else if (mBmData[3].rightBearing - mBmData[3].leftBearing > 0) {
|
2008-01-03 07:21:36 +03:00
|
|
|
// glue is present
|
2014-02-13 18:53:52 +04:00
|
|
|
nsBoundingMetrics& bm = mBmData[3];
|
2008-04-23 07:13:09 +04:00
|
|
|
// Ensure the stride for the glue is not reduced to less than one pixel
|
|
|
|
if (bm.rightBearing - bm.leftBearing >= 3 * oneDevPixel) {
|
|
|
|
// To protect against gaps, pretend the glue is smaller than it is,
|
|
|
|
// in order to trim off ends and thus get a solid edge for the join.
|
|
|
|
bm.leftBearing += oneDevPixel;
|
|
|
|
bm.rightBearing -= oneDevPixel;
|
2006-10-06 19:38:17 +04:00
|
|
|
}
|
2008-04-23 07:13:09 +04:00
|
|
|
|
|
|
|
nsRect clipRect = unionRect;
|
|
|
|
|
2014-02-13 18:53:52 +04:00
|
|
|
for (i = 0; i < 2; ++i) {
|
2008-04-23 07:13:09 +04:00
|
|
|
// Make sure not to draw outside the character
|
2013-01-15 16:22:03 +04:00
|
|
|
nscoord dx = std::max(end[i], aRect.x);
|
|
|
|
nscoord fillEnd = std::min(start[i+1], aRect.XMost());
|
2008-04-23 07:13:09 +04:00
|
|
|
while (dx < fillEnd) {
|
|
|
|
clipRect.x = dx;
|
2013-01-15 16:22:03 +04:00
|
|
|
clipRect.width = std::min(bm.rightBearing - bm.leftBearing, fillEnd - dx);
|
2014-02-13 18:53:52 +04:00
|
|
|
AutoPushClipRect clip(aThebesContext, oneDevPixel, clipRect);
|
2008-04-23 07:13:09 +04:00
|
|
|
dx -= bm.leftBearing;
|
2016-04-19 19:13:28 +03:00
|
|
|
mGlyphs[3]->Draw(Range(mGlyphs[3].get()), gfxPoint(dx, dy), params);
|
2008-04-23 07:13:09 +04:00
|
|
|
dx += bm.rightBearing;
|
1999-11-17 03:49:37 +03:00
|
|
|
}
|
2001-02-02 12:40:53 +03:00
|
|
|
}
|
1999-11-17 03:49:37 +03:00
|
|
|
}
|
2008-01-03 07:21:36 +03:00
|
|
|
#ifdef DEBUG
|
|
|
|
else { // no glue
|
2014-02-13 18:53:52 +04:00
|
|
|
for (i = 0; i < 2; ++i) {
|
2008-04-23 07:13:09 +04:00
|
|
|
NS_ASSERTION(end[i] >= start[i+1],
|
|
|
|
"gap between parts with missing glue glyph");
|
|
|
|
}
|
2008-01-03 07:21:36 +03:00
|
|
|
}
|
|
|
|
#endif
|
2000-03-28 13:38:24 +04:00
|
|
|
return NS_OK;
|
1999-11-17 03:49:37 +03:00
|
|
|
}
|