2007-03-22 10:30:00 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
|
|
|
* ***** BEGIN LICENSE BLOCK *****
|
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
* the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/MPL/
|
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
|
|
|
*
|
|
|
|
* The Original Code is Novell code.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is Novell Corporation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 2006
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
|
|
|
* robert@ocallahan.org
|
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
|
|
|
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
|
|
|
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
|
|
|
|
|
|
|
#include "nsTextRunTransformations.h"
|
|
|
|
|
|
|
|
#include "nsTextFrameUtils.h"
|
|
|
|
#include "gfxSkipChars.h"
|
|
|
|
|
|
|
|
#include "nsStyleConsts.h"
|
|
|
|
#include "nsStyleContext.h"
|
|
|
|
#include "gfxContext.h"
|
2007-07-02 16:36:59 -07:00
|
|
|
#include "nsContentUtils.h"
|
2010-07-29 12:22:16 -07:00
|
|
|
#include "nsUnicharUtils.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
#define SZLIG 0x00DF
|
|
|
|
|
2007-11-15 17:43:47 -08:00
|
|
|
nsTransformedTextRun *
|
|
|
|
nsTransformedTextRun::Create(const gfxTextRunFactory::Parameters* aParams,
|
|
|
|
nsTransformingTextRunFactory* aFactory,
|
|
|
|
gfxFontGroup* aFontGroup,
|
|
|
|
const PRUnichar* aString, PRUint32 aLength,
|
|
|
|
const PRUint32 aFlags, nsStyleContext** aStyles,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool aOwnsFactory)
|
2007-11-15 17:43:47 -08:00
|
|
|
{
|
2010-02-18 03:52:34 -08:00
|
|
|
NS_ASSERTION(!(aFlags & gfxTextRunFactory::TEXT_IS_8BIT),
|
|
|
|
"didn't expect text to be marked as 8-bit here");
|
|
|
|
|
2012-01-05 03:54:45 -08:00
|
|
|
void *storage = AllocateStorageForTextRun(sizeof(nsTransformedTextRun), aLength);
|
|
|
|
if (!storage) {
|
2010-02-18 03:52:34 -08:00
|
|
|
return nsnull;
|
|
|
|
}
|
|
|
|
|
2012-01-05 03:54:45 -08:00
|
|
|
return new (storage) nsTransformedTextRun(aParams, aFactory, aFontGroup,
|
|
|
|
aString, aLength,
|
|
|
|
aFlags, aStyles, aOwnsFactory);
|
2007-11-15 17:43:47 -08:00
|
|
|
}
|
|
|
|
|
2007-11-11 17:51:31 -08:00
|
|
|
void
|
|
|
|
nsTransformedTextRun::SetCapitalization(PRUint32 aStart, PRUint32 aLength,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool* aCapitalization,
|
2007-06-26 21:22:21 -07:00
|
|
|
gfxContext* aRefContext)
|
2007-11-11 17:51:31 -08:00
|
|
|
{
|
|
|
|
if (mCapitalize.IsEmpty()) {
|
|
|
|
if (!mCapitalize.AppendElements(GetLength()))
|
|
|
|
return;
|
2011-09-28 23:19:26 -07:00
|
|
|
memset(mCapitalize.Elements(), 0, GetLength()*sizeof(bool));
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2011-09-28 23:19:26 -07:00
|
|
|
memcpy(mCapitalize.Elements() + aStart, aCapitalization, aLength*sizeof(bool));
|
2011-10-17 07:59:28 -07:00
|
|
|
mNeedsRebuild = true;
|
2007-11-11 17:51:31 -08:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2007-11-11 17:51:31 -08:00
|
|
|
nsTransformedTextRun::SetPotentialLineBreaks(PRUint32 aStart, PRUint32 aLength,
|
2011-08-01 18:20:52 -07:00
|
|
|
PRUint8* aBreakBefore,
|
2007-11-11 17:51:31 -08:00
|
|
|
gfxContext* aRefContext)
|
|
|
|
{
|
2011-09-28 23:19:26 -07:00
|
|
|
bool changed = gfxTextRun::SetPotentialLineBreaks(aStart, aLength,
|
2007-11-11 17:51:31 -08:00
|
|
|
aBreakBefore, aRefContext);
|
2009-01-08 16:23:28 -08:00
|
|
|
if (changed) {
|
2011-10-17 07:59:28 -07:00
|
|
|
mNeedsRebuild = true;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2009-01-08 16:23:28 -08:00
|
|
|
return changed;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2011-11-27 19:03:14 -08:00
|
|
|
size_t
|
|
|
|
nsTransformedTextRun::SizeOfExcludingThis(nsMallocSizeOfFun aMallocSizeOf)
|
2011-10-14 00:06:35 -07:00
|
|
|
{
|
2011-11-27 19:03:14 -08:00
|
|
|
size_t total = gfxTextRun::SizeOfExcludingThis(aMallocSizeOf);
|
2011-12-15 14:59:53 -08:00
|
|
|
total += mStyles.SizeOfExcludingThis(aMallocSizeOf);
|
|
|
|
total += mCapitalize.SizeOfExcludingThis(aMallocSizeOf);
|
2011-10-14 00:06:35 -07:00
|
|
|
if (mOwnsFactory) {
|
2012-01-25 00:52:51 -08:00
|
|
|
total += aMallocSizeOf(mFactory);
|
2011-10-14 00:06:35 -07:00
|
|
|
}
|
|
|
|
return total;
|
|
|
|
}
|
|
|
|
|
2011-11-27 19:03:14 -08:00
|
|
|
size_t
|
|
|
|
nsTransformedTextRun::SizeOfIncludingThis(nsMallocSizeOfFun aMallocSizeOf)
|
|
|
|
{
|
2012-01-25 00:52:51 -08:00
|
|
|
return aMallocSizeOf(this) + SizeOfExcludingThis(aMallocSizeOf);
|
2011-11-27 19:03:14 -08:00
|
|
|
}
|
|
|
|
|
2009-01-16 00:17:46 -08:00
|
|
|
nsTransformedTextRun*
|
2007-03-22 16:13:12 -07:00
|
|
|
nsTransformingTextRunFactory::MakeTextRun(const PRUnichar* aString, PRUint32 aLength,
|
2007-05-09 15:04:56 -07:00
|
|
|
const gfxTextRunFactory::Parameters* aParams,
|
|
|
|
gfxFontGroup* aFontGroup, PRUint32 aFlags,
|
2011-09-28 23:19:26 -07:00
|
|
|
nsStyleContext** aStyles, bool aOwnsFactory)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2009-01-08 16:23:28 -08:00
|
|
|
return nsTransformedTextRun::Create(aParams, this, aFontGroup,
|
|
|
|
aString, aLength, aFlags, aStyles, aOwnsFactory);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2009-01-16 00:17:46 -08:00
|
|
|
nsTransformedTextRun*
|
2007-03-22 16:13:12 -07:00
|
|
|
nsTransformingTextRunFactory::MakeTextRun(const PRUint8* aString, PRUint32 aLength,
|
2007-05-09 15:04:56 -07:00
|
|
|
const gfxTextRunFactory::Parameters* aParams,
|
|
|
|
gfxFontGroup* aFontGroup, PRUint32 aFlags,
|
2011-09-28 23:19:26 -07:00
|
|
|
nsStyleContext** aStyles, bool aOwnsFactory)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2007-03-22 16:13:12 -07:00
|
|
|
// We'll only have a Unicode code path to minimize the amount of code needed
|
|
|
|
// for these rarely used features
|
2007-07-08 00:08:04 -07:00
|
|
|
NS_ConvertASCIItoUTF16 unicodeString(reinterpret_cast<const char*>(aString), aLength);
|
2007-05-09 15:04:56 -07:00
|
|
|
return MakeTextRun(unicodeString.get(), aLength, aParams, aFontGroup,
|
|
|
|
aFlags & ~(gfxFontGroup::TEXT_IS_PERSISTENT | gfxFontGroup::TEXT_IS_8BIT),
|
2007-05-14 20:56:47 -07:00
|
|
|
aStyles, aOwnsFactory);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2007-03-22 16:13:12 -07:00
|
|
|
/**
|
|
|
|
* Copy a given textrun, but merge certain characters into a single logical
|
|
|
|
* character. Glyphs for a character are added to the glyph list for the previous
|
|
|
|
* character and then the merged character is eliminated. Visually the results
|
|
|
|
* are identical.
|
|
|
|
*
|
|
|
|
* This is used for text-transform:uppercase when we encounter a SZLIG,
|
|
|
|
* whose uppercase form is "SS".
|
|
|
|
*
|
|
|
|
* This function is unable to merge characters when they occur in different
|
|
|
|
* glyph runs. It's hard to see how this could happen, but if it does, we just
|
|
|
|
* discard the characters-to-merge.
|
|
|
|
*
|
2007-11-08 22:27:23 -08:00
|
|
|
* For simplicity, this produces a textrun containing all DetailedGlyphs,
|
|
|
|
* no simple glyphs. So don't call it unless you really have merging to do.
|
|
|
|
*
|
2007-03-22 16:13:12 -07:00
|
|
|
* @param aCharsToMerge when aCharsToMerge[i] is true, this character is
|
|
|
|
* merged into the previous character
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
MergeCharactersInTextRun(gfxTextRun* aDest, gfxTextRun* aSrc,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool* aCharsToMerge)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2007-03-22 16:13:12 -07:00
|
|
|
aDest->ResetGlyphRuns();
|
|
|
|
|
2007-11-08 22:27:23 -08:00
|
|
|
gfxTextRun::GlyphRunIterator iter(aSrc, 0, aSrc->GetLength());
|
2007-03-22 16:13:12 -07:00
|
|
|
PRUint32 offset = 0;
|
2007-11-08 22:27:23 -08:00
|
|
|
nsAutoTArray<gfxTextRun::DetailedGlyph,2> glyphs;
|
|
|
|
while (iter.NextRun()) {
|
|
|
|
gfxTextRun::GlyphRun* run = iter.GetGlyphRun();
|
2011-06-15 23:31:37 -07:00
|
|
|
nsresult rv = aDest->AddGlyphRun(run->mFont, run->mMatchType,
|
2011-10-17 07:59:28 -07:00
|
|
|
offset, false);
|
2007-03-22 16:13:12 -07:00
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return;
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool anyMissing = false;
|
2007-11-08 22:27:23 -08:00
|
|
|
PRUint32 mergeRunStart = iter.GetStringStart();
|
2007-03-22 16:13:12 -07:00
|
|
|
PRUint32 k;
|
2007-11-08 22:27:23 -08:00
|
|
|
for (k = iter.GetStringStart(); k < iter.GetStringEnd(); ++k) {
|
|
|
|
gfxTextRun::CompressedGlyph g = aSrc->GetCharacterGlyphs()[k];
|
|
|
|
if (g.IsSimpleGlyph()) {
|
|
|
|
if (!anyMissing) {
|
|
|
|
gfxTextRun::DetailedGlyph details;
|
|
|
|
details.mGlyphID = g.GetSimpleGlyph();
|
|
|
|
details.mAdvance = g.GetSimpleAdvance();
|
|
|
|
details.mXOffset = 0;
|
|
|
|
details.mYOffset = 0;
|
|
|
|
glyphs.AppendElement(details);
|
2007-11-07 23:41:06 -08:00
|
|
|
}
|
2007-11-08 22:27:23 -08:00
|
|
|
} else {
|
|
|
|
if (g.IsMissing()) {
|
2011-10-17 07:59:28 -07:00
|
|
|
anyMissing = true;
|
2007-11-08 22:27:23 -08:00
|
|
|
glyphs.Clear();
|
2007-11-07 23:41:06 -08:00
|
|
|
}
|
2011-02-11 14:05:09 -08:00
|
|
|
if (g.GetGlyphCount() > 0) {
|
|
|
|
glyphs.AppendElements(aSrc->GetDetailedGlyphs(k), g.GetGlyphCount());
|
|
|
|
}
|
2007-11-08 22:27:23 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
// We could teach this method to handle merging of characters that aren't
|
|
|
|
// cluster starts or ligature group starts, but this is really only used
|
|
|
|
// to merge S's (uppercase ß), so it's not worth it.
|
|
|
|
|
|
|
|
if (k + 1 < iter.GetStringEnd() && aCharsToMerge[k + 1]) {
|
2009-07-29 19:59:41 -07:00
|
|
|
NS_ASSERTION(g.IsClusterStart() && g.IsLigatureGroupStart(),
|
2007-11-08 22:27:23 -08:00
|
|
|
"Don't know how to merge this stuff");
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_ASSERTION(mergeRunStart == k ||
|
2009-07-29 19:59:41 -07:00
|
|
|
(g.IsClusterStart() && g.IsLigatureGroupStart()),
|
2007-11-08 22:27:23 -08:00
|
|
|
"Don't know how to merge this stuff");
|
|
|
|
|
2008-01-09 15:33:34 -08:00
|
|
|
// If the start of the merge run is actually a character that should
|
|
|
|
// have been merged with the previous character (this can happen
|
|
|
|
// if there's a font change in the middle of a szlig, for example),
|
|
|
|
// just discard the entire merge run. See comment at start of this
|
|
|
|
// function.
|
|
|
|
if (!aCharsToMerge[mergeRunStart]) {
|
|
|
|
if (anyMissing) {
|
|
|
|
g.SetMissing(glyphs.Length());
|
|
|
|
} else {
|
2011-10-17 07:59:28 -07:00
|
|
|
g.SetComplex(true, true, glyphs.Length());
|
2008-01-09 15:33:34 -08:00
|
|
|
}
|
|
|
|
aDest->SetGlyphs(offset, g, glyphs.Elements());
|
|
|
|
++offset;
|
2007-03-22 16:13:12 -07:00
|
|
|
}
|
2008-01-09 15:33:34 -08:00
|
|
|
|
2007-11-08 22:27:23 -08:00
|
|
|
glyphs.Clear();
|
2011-10-17 07:59:28 -07:00
|
|
|
anyMissing = false;
|
2007-11-08 22:27:23 -08:00
|
|
|
mergeRunStart = k + 1;
|
2007-03-22 16:13:12 -07:00
|
|
|
}
|
2007-11-08 22:27:23 -08:00
|
|
|
NS_ASSERTION(glyphs.Length() == 0,
|
|
|
|
"Leftover glyphs, don't request merging of the last character with its next!");
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2007-03-22 16:13:12 -07:00
|
|
|
NS_ASSERTION(offset == aDest->GetLength(), "Bad offset calculations");
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static gfxTextRunFactory::Parameters
|
2007-06-26 21:22:21 -07:00
|
|
|
GetParametersForInner(nsTransformedTextRun* aTextRun, PRUint32* aFlags,
|
|
|
|
gfxContext* aRefContext)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
gfxTextRunFactory::Parameters params =
|
2007-06-26 21:22:21 -07:00
|
|
|
{ aRefContext, nsnull, nsnull,
|
2009-01-08 16:23:28 -08:00
|
|
|
nsnull, 0, aTextRun->GetAppUnitsPerDevUnit()
|
2007-05-09 15:04:56 -07:00
|
|
|
};
|
|
|
|
*aFlags = aTextRun->GetFlags() & ~gfxFontGroup::TEXT_IS_PERSISTENT;
|
2007-03-22 10:30:00 -07:00
|
|
|
return params;
|
|
|
|
}
|
|
|
|
|
2007-03-22 16:13:12 -07:00
|
|
|
void
|
2007-06-26 21:22:21 -07:00
|
|
|
nsFontVariantTextRunFactory::RebuildTextRun(nsTransformedTextRun* aTextRun,
|
|
|
|
gfxContext* aRefContext)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2007-05-09 15:04:56 -07:00
|
|
|
gfxFontGroup* fontGroup = aTextRun->GetFontGroup();
|
|
|
|
gfxFontStyle fontStyle = *fontGroup->GetStyle();
|
2007-03-22 10:30:00 -07:00
|
|
|
fontStyle.size *= 0.8;
|
2007-05-09 15:04:56 -07:00
|
|
|
nsRefPtr<gfxFontGroup> smallFont = fontGroup->Copy(&fontStyle);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (!smallFont)
|
2007-03-22 16:13:12 -07:00
|
|
|
return;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2007-05-09 15:04:56 -07:00
|
|
|
PRUint32 flags;
|
2007-06-26 21:22:21 -07:00
|
|
|
gfxTextRunFactory::Parameters innerParams =
|
|
|
|
GetParametersForInner(aTextRun, &flags, aRefContext);
|
2007-03-22 16:13:12 -07:00
|
|
|
|
|
|
|
PRUint32 length = aTextRun->GetLength();
|
2011-12-06 04:39:19 -08:00
|
|
|
const PRUnichar* str = aTextRun->mString.BeginReading();
|
2007-03-22 16:13:12 -07:00
|
|
|
nsRefPtr<nsStyleContext>* styles = aTextRun->mStyles.Elements();
|
|
|
|
// Create a textrun so we can check cluster-start properties
|
2011-12-06 04:39:18 -08:00
|
|
|
nsAutoPtr<gfxTextRun> inner(fontGroup->MakeTextRun(str, length, &innerParams, flags));
|
2007-07-03 20:39:01 -07:00
|
|
|
if (!inner.get())
|
2007-03-22 16:13:12 -07:00
|
|
|
return;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
nsCaseTransformTextRunFactory uppercaseFactory(nsnull, true);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2007-03-22 16:13:12 -07:00
|
|
|
aTextRun->ResetGlyphRuns();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
PRUint32 runStart = 0;
|
2011-09-28 23:19:26 -07:00
|
|
|
bool runIsLowercase = false;
|
2007-03-22 16:13:12 -07:00
|
|
|
nsAutoTArray<nsStyleContext*,50> styleArray;
|
2011-08-01 18:20:52 -07:00
|
|
|
nsAutoTArray<PRUint8,50> canBreakBeforeArray;
|
2007-03-22 16:13:12 -07:00
|
|
|
|
|
|
|
PRUint32 i;
|
|
|
|
for (i = 0; i <= length; ++i) {
|
2011-09-28 23:19:26 -07:00
|
|
|
bool isLowercase = false;
|
2007-03-22 16:13:12 -07:00
|
|
|
if (i < length) {
|
2007-03-22 10:30:00 -07:00
|
|
|
// Characters that aren't the start of a cluster are ignored here. They
|
|
|
|
// get added to whatever lowercase/non-lowercase run we're in.
|
2007-06-13 11:28:38 -07:00
|
|
|
if (!inner->IsClusterStart(i)) {
|
|
|
|
isLowercase = runIsLowercase;
|
2007-03-22 10:30:00 -07:00
|
|
|
} else {
|
2007-06-13 11:28:38 -07:00
|
|
|
if (styles[i]->GetStyleFont()->mFont.variant == NS_STYLE_FONT_VARIANT_SMALL_CAPS) {
|
|
|
|
PRUnichar ch = str[i];
|
|
|
|
PRUnichar ch2;
|
2010-07-29 12:22:16 -07:00
|
|
|
ch2 = ToUpperCase(ch);
|
2007-06-13 11:28:38 -07:00
|
|
|
isLowercase = ch != ch2 || ch == SZLIG;
|
|
|
|
} else {
|
|
|
|
// Don't transform the character! I.e., pretend that it's not lowercase
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-03-22 16:13:12 -07:00
|
|
|
if ((i == length || runIsLowercase != isLowercase) && runStart < i) {
|
2009-01-16 00:17:46 -08:00
|
|
|
nsAutoPtr<nsTransformedTextRun> transformedChild;
|
2011-12-06 04:39:18 -08:00
|
|
|
nsAutoPtr<gfxTextRun> cachedChild;
|
2007-07-03 20:39:01 -07:00
|
|
|
gfxTextRun* child;
|
2009-01-08 16:23:28 -08:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
if (runIsLowercase) {
|
2007-07-03 20:39:01 -07:00
|
|
|
transformedChild = uppercaseFactory.MakeTextRun(str + runStart, i - runStart,
|
2011-10-17 07:59:28 -07:00
|
|
|
&innerParams, smallFont, flags, styleArray.Elements(), false);
|
2007-07-03 20:39:01 -07:00
|
|
|
child = transformedChild;
|
2007-03-22 10:30:00 -07:00
|
|
|
} else {
|
2007-07-03 20:39:01 -07:00
|
|
|
cachedChild =
|
2011-12-06 04:39:18 -08:00
|
|
|
fontGroup->MakeTextRun(str + runStart, i - runStart,
|
|
|
|
&innerParams, flags);
|
2007-07-03 20:39:01 -07:00
|
|
|
child = cachedChild.get();
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2007-03-22 16:13:12 -07:00
|
|
|
if (!child)
|
|
|
|
return;
|
|
|
|
// Copy potential linebreaks into child so they're preserved
|
|
|
|
// (and also child will be shaped appropriately)
|
|
|
|
NS_ASSERTION(canBreakBeforeArray.Length() == i - runStart,
|
|
|
|
"lost some break-before values?");
|
2007-06-26 21:22:21 -07:00
|
|
|
child->SetPotentialLineBreaks(0, canBreakBeforeArray.Length(),
|
|
|
|
canBreakBeforeArray.Elements(), aRefContext);
|
2009-01-16 00:17:46 -08:00
|
|
|
if (transformedChild) {
|
|
|
|
transformedChild->FinishSettingProperties(aRefContext);
|
|
|
|
}
|
2011-02-09 22:50:47 -08:00
|
|
|
aTextRun->CopyGlyphDataFrom(child, 0, child->GetLength(), runStart);
|
2007-03-22 16:13:12 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
runStart = i;
|
2007-03-22 16:13:12 -07:00
|
|
|
styleArray.Clear();
|
|
|
|
canBreakBeforeArray.Clear();
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2007-03-22 16:13:12 -07:00
|
|
|
|
|
|
|
if (i < length) {
|
2007-05-23 02:37:52 -07:00
|
|
|
runIsLowercase = isLowercase;
|
2007-03-22 16:13:12 -07:00
|
|
|
styleArray.AppendElement(styles[i]);
|
|
|
|
canBreakBeforeArray.AppendElement(aTextRun->CanBreakLineBefore(i));
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
2007-03-22 16:13:12 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2007-03-22 16:13:12 -07:00
|
|
|
void
|
2007-06-26 21:22:21 -07:00
|
|
|
nsCaseTransformTextRunFactory::RebuildTextRun(nsTransformedTextRun* aTextRun,
|
|
|
|
gfxContext* aRefContext)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2007-03-22 16:13:12 -07:00
|
|
|
PRUint32 length = aTextRun->GetLength();
|
2011-12-06 04:39:19 -08:00
|
|
|
const PRUnichar* str = aTextRun->mString.BeginReading();
|
2007-03-22 16:13:12 -07:00
|
|
|
nsRefPtr<nsStyleContext>* styles = aTextRun->mStyles.Elements();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
nsAutoString convertedString;
|
2011-09-28 23:19:26 -07:00
|
|
|
nsAutoTArray<bool,50> charsToMergeArray;
|
2007-03-22 16:13:12 -07:00
|
|
|
nsAutoTArray<nsStyleContext*,50> styleArray;
|
2011-08-01 18:20:52 -07:00
|
|
|
nsAutoTArray<PRUint8,50> canBreakBeforeArray;
|
2007-03-22 16:13:12 -07:00
|
|
|
PRUint32 extraCharsCount = 0;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2007-03-22 16:13:12 -07:00
|
|
|
PRUint32 i;
|
|
|
|
for (i = 0; i < length; ++i) {
|
|
|
|
PRUnichar ch = str[i];
|
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
charsToMergeArray.AppendElement(false);
|
2007-03-22 16:13:12 -07:00
|
|
|
styleArray.AppendElement(styles[i]);
|
|
|
|
canBreakBeforeArray.AppendElement(aTextRun->CanBreakLineBefore(i));
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2007-03-22 16:13:12 -07:00
|
|
|
PRUint8 style = mAllUppercase ? NS_STYLE_TEXT_TRANSFORM_UPPERCASE
|
|
|
|
: styles[i]->GetStyleText()->mTextTransform;
|
2011-09-28 23:19:26 -07:00
|
|
|
bool extraChar = false;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
switch (style) {
|
|
|
|
case NS_STYLE_TEXT_TRANSFORM_LOWERCASE:
|
2010-07-29 12:22:16 -07:00
|
|
|
ch = ToLowerCase(ch);
|
2007-03-22 10:30:00 -07:00
|
|
|
break;
|
|
|
|
case NS_STYLE_TEXT_TRANSFORM_UPPERCASE:
|
|
|
|
if (ch == SZLIG) {
|
|
|
|
convertedString.Append('S');
|
2011-10-17 07:59:28 -07:00
|
|
|
extraChar = true;
|
2007-03-22 10:30:00 -07:00
|
|
|
ch = 'S';
|
|
|
|
} else {
|
2010-07-29 12:22:16 -07:00
|
|
|
ch = ToUpperCase(ch);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case NS_STYLE_TEXT_TRANSFORM_CAPITALIZE:
|
2007-11-11 17:51:31 -08:00
|
|
|
if (i < aTextRun->mCapitalize.Length() && aTextRun->mCapitalize[i]) {
|
2007-03-22 10:30:00 -07:00
|
|
|
if (ch == SZLIG) {
|
|
|
|
convertedString.Append('S');
|
2011-10-17 07:59:28 -07:00
|
|
|
extraChar = true;
|
2007-03-22 10:30:00 -07:00
|
|
|
ch = 'S';
|
|
|
|
} else {
|
2010-07-29 12:22:16 -07:00
|
|
|
ch = ToTitleCase(ch);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
convertedString.Append(ch);
|
2007-03-22 16:13:12 -07:00
|
|
|
if (extraChar) {
|
|
|
|
++extraCharsCount;
|
2011-10-17 07:59:28 -07:00
|
|
|
charsToMergeArray.AppendElement(true);
|
2007-03-22 16:13:12 -07:00
|
|
|
styleArray.AppendElement(styles[i]);
|
2011-10-17 07:59:28 -07:00
|
|
|
canBreakBeforeArray.AppendElement(false);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-05-09 15:04:56 -07:00
|
|
|
PRUint32 flags;
|
2007-06-26 21:22:21 -07:00
|
|
|
gfxTextRunFactory::Parameters innerParams =
|
|
|
|
GetParametersForInner(aTextRun, &flags, aRefContext);
|
2007-05-09 15:04:56 -07:00
|
|
|
gfxFontGroup* fontGroup = aTextRun->GetFontGroup();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2009-01-16 00:17:46 -08:00
|
|
|
nsAutoPtr<nsTransformedTextRun> transformedChild;
|
2011-12-06 04:39:18 -08:00
|
|
|
nsAutoPtr<gfxTextRun> cachedChild;
|
2007-07-03 20:39:01 -07:00
|
|
|
gfxTextRun* child;
|
2009-01-08 16:23:28 -08:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
if (mInnerTransformingTextRunFactory) {
|
2007-07-03 20:39:01 -07:00
|
|
|
transformedChild = mInnerTransformingTextRunFactory->MakeTextRun(
|
2007-03-22 16:13:12 -07:00
|
|
|
convertedString.BeginReading(), convertedString.Length(),
|
2011-10-17 07:59:28 -07:00
|
|
|
&innerParams, fontGroup, flags, styleArray.Elements(), false);
|
2007-07-03 20:39:01 -07:00
|
|
|
child = transformedChild.get();
|
2007-03-22 16:13:12 -07:00
|
|
|
} else {
|
2011-12-06 04:39:18 -08:00
|
|
|
cachedChild = fontGroup->MakeTextRun(
|
|
|
|
convertedString.BeginReading(), convertedString.Length(),
|
2007-07-03 20:39:01 -07:00
|
|
|
&innerParams, flags);
|
|
|
|
child = cachedChild.get();
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2007-03-22 16:13:12 -07:00
|
|
|
if (!child)
|
|
|
|
return;
|
|
|
|
// Copy potential linebreaks into child so they're preserved
|
|
|
|
// (and also child will be shaped appropriately)
|
|
|
|
NS_ASSERTION(convertedString.Length() == canBreakBeforeArray.Length(),
|
|
|
|
"Dropped characters or break-before values somewhere!");
|
2007-06-26 21:22:21 -07:00
|
|
|
child->SetPotentialLineBreaks(0, canBreakBeforeArray.Length(),
|
|
|
|
canBreakBeforeArray.Elements(), aRefContext);
|
2009-01-16 00:17:46 -08:00
|
|
|
if (transformedChild) {
|
|
|
|
transformedChild->FinishSettingProperties(aRefContext);
|
|
|
|
}
|
2007-11-08 22:27:23 -08:00
|
|
|
|
|
|
|
if (extraCharsCount > 0) {
|
|
|
|
// Now merge multiple characters into one multi-glyph character as required
|
|
|
|
MergeCharactersInTextRun(aTextRun, child, charsToMergeArray.Elements());
|
|
|
|
} else {
|
|
|
|
// No merging to do, so just copy; this produces a more optimized textrun.
|
|
|
|
// We can't steal the data because the child may be cached and stealing
|
|
|
|
// the data would break the cache.
|
|
|
|
aTextRun->ResetGlyphRuns();
|
2011-02-09 22:50:47 -08:00
|
|
|
aTextRun->CopyGlyphDataFrom(child, 0, child->GetLength(), 0);
|
2007-11-08 22:27:23 -08:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|