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