2010-03-15 09:34:25 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
2012-05-21 11:12:37 +00: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/. */
|
2010-03-15 09:34:25 +00:00
|
|
|
|
|
|
|
//#define FORCE_PR_LOG
|
|
|
|
|
|
|
|
#include "gfxGDIShaper.h"
|
|
|
|
|
|
|
|
/**********************************************************************
|
|
|
|
*
|
|
|
|
* class gfxGDIShaper
|
|
|
|
*
|
|
|
|
**********************************************************************/
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool
|
2013-01-04 18:35:37 +00:00
|
|
|
gfxGDIShaper::ShapeText(gfxContext *aContext,
|
|
|
|
const PRUnichar *aText,
|
|
|
|
uint32_t aOffset,
|
|
|
|
uint32_t aLength,
|
|
|
|
int32_t aScript,
|
|
|
|
gfxShapedText *aShapedText)
|
2010-03-15 09:34:25 +00:00
|
|
|
{
|
|
|
|
DCFromContext dc(aContext);
|
2011-10-25 12:30:02 +00:00
|
|
|
AutoSelectFont selectFont(dc, static_cast<gfxGDIFont*>(mFont)->GetHFONT());
|
2010-03-15 09:34:25 +00:00
|
|
|
|
2013-01-04 18:35:37 +00:00
|
|
|
uint32_t length = aLength;
|
2010-03-15 09:34:25 +00:00
|
|
|
nsAutoTArray<WORD,500> glyphArray;
|
2011-12-06 12:39:19 +00:00
|
|
|
if (!glyphArray.SetLength(length)) {
|
2011-10-17 14:59:28 +00:00
|
|
|
return false;
|
2010-03-15 09:34:25 +00:00
|
|
|
}
|
|
|
|
WORD *glyphs = glyphArray.Elements();
|
|
|
|
|
2013-01-04 18:35:37 +00:00
|
|
|
DWORD ret = ::GetGlyphIndicesW(dc, aText, length,
|
2010-03-15 09:34:25 +00:00
|
|
|
glyphs, GGI_MARK_NONEXISTING_GLYPHS);
|
|
|
|
if (ret == GDI_ERROR) {
|
2011-10-17 14:59:28 +00:00
|
|
|
return false;
|
2010-03-15 09:34:25 +00:00
|
|
|
}
|
2010-06-25 12:43:10 +00:00
|
|
|
|
2011-12-06 12:39:19 +00:00
|
|
|
for (int k = 0; k < length; k++) {
|
2010-06-25 12:43:10 +00:00
|
|
|
if (glyphs[k] == 0xFFFF)
|
2011-10-17 14:59:28 +00:00
|
|
|
return false;
|
2010-06-25 12:43:10 +00:00
|
|
|
}
|
2010-03-15 09:34:25 +00:00
|
|
|
|
|
|
|
SIZE size;
|
|
|
|
nsAutoTArray<int,500> partialWidthArray;
|
2011-12-06 12:39:19 +00:00
|
|
|
if (!partialWidthArray.SetLength(length)) {
|
2011-10-17 14:59:28 +00:00
|
|
|
return false;
|
2010-03-15 09:34:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
BOOL success = ::GetTextExtentExPointI(dc,
|
|
|
|
glyphs,
|
2011-12-06 12:39:19 +00:00
|
|
|
length,
|
2010-03-15 09:34:25 +00:00
|
|
|
INT_MAX,
|
|
|
|
NULL,
|
|
|
|
partialWidthArray.Elements(),
|
|
|
|
&size);
|
|
|
|
if (!success) {
|
2011-10-17 14:59:28 +00:00
|
|
|
return false;
|
2010-03-15 09:34:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
gfxTextRun::CompressedGlyph g;
|
2013-01-04 18:35:37 +00:00
|
|
|
gfxTextRun::CompressedGlyph *charGlyphs =
|
|
|
|
aShapedText->GetCharacterGlyphs();
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t i;
|
|
|
|
int32_t lastWidth = 0;
|
2013-02-19 21:46:27 +00:00
|
|
|
int32_t appUnitsPerDevPixel = aShapedText->GetAppUnitsPerDevUnit();
|
2011-12-06 12:39:19 +00:00
|
|
|
for (i = 0; i < length; ++i) {
|
2013-01-04 18:35:37 +00:00
|
|
|
uint32_t offset = aOffset + i;
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t advancePixels = partialWidthArray[i] - lastWidth;
|
2010-03-15 09:34:25 +00:00
|
|
|
lastWidth = partialWidthArray[i];
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t advanceAppUnits = advancePixels * appUnitsPerDevPixel;
|
2010-03-15 09:34:25 +00:00
|
|
|
WCHAR glyph = glyphs[i];
|
2013-01-04 18:35:37 +00:00
|
|
|
NS_ASSERTION(!gfxFontGroup::IsInvalidChar(aText[i]),
|
2010-03-15 09:34:25 +00:00
|
|
|
"Invalid character detected!");
|
2013-01-04 18:35:37 +00:00
|
|
|
bool atClusterStart = charGlyphs[offset].IsClusterStart();
|
2010-03-15 09:34:25 +00:00
|
|
|
if (advanceAppUnits >= 0 &&
|
2011-12-06 12:39:19 +00:00
|
|
|
gfxShapedWord::CompressedGlyph::IsSimpleAdvance(advanceAppUnits) &&
|
|
|
|
gfxShapedWord::CompressedGlyph::IsSimpleGlyphID(glyph) &&
|
2010-12-22 14:27:43 +00:00
|
|
|
atClusterStart)
|
|
|
|
{
|
2013-01-04 18:35:37 +00:00
|
|
|
charGlyphs[offset].SetSimpleGlyph(advanceAppUnits, glyph);
|
2010-03-15 09:34:25 +00:00
|
|
|
} else {
|
2013-01-04 18:35:37 +00:00
|
|
|
gfxShapedText::DetailedGlyph details;
|
2010-03-15 09:34:25 +00:00
|
|
|
details.mGlyphID = glyph;
|
|
|
|
details.mAdvance = advanceAppUnits;
|
|
|
|
details.mXOffset = 0;
|
|
|
|
details.mYOffset = 0;
|
2013-01-04 18:35:37 +00:00
|
|
|
aShapedText->SetGlyphs(offset,
|
2011-12-06 12:39:19 +00:00
|
|
|
g.SetComplex(atClusterStart, true, 1),
|
|
|
|
&details);
|
2010-03-15 09:34:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-10-17 14:59:28 +00:00
|
|
|
return true;
|
2010-03-15 09:34:25 +00:00
|
|
|
}
|