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
|
2011-12-06 04:39:19 -08:00
|
|
|
gfxGDIShaper::ShapeWord(gfxContext *aContext,
|
|
|
|
gfxShapedWord *aShapedWord,
|
|
|
|
const PRUnichar *aString)
|
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
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t length = aShapedWord->Length();
|
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();
|
|
|
|
|
2011-12-06 04:39:19 -08:00
|
|
|
DWORD ret = ::GetGlyphIndicesW(dc, aString, 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;
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t i;
|
|
|
|
int32_t lastWidth = 0;
|
|
|
|
uint32_t appUnitsPerDevPixel = aShapedWord->AppUnitsPerDevUnit();
|
2011-12-06 04:39:19 -08:00
|
|
|
for (i = 0; i < length; ++i) {
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t offset = i;
|
|
|
|
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];
|
2011-12-06 04:39:19 -08:00
|
|
|
NS_ASSERTION(!gfxFontGroup::IsInvalidChar(aShapedWord->GetCharAt(offset)),
|
2010-03-15 02:34:25 -07:00
|
|
|
"Invalid character detected!");
|
2011-12-06 04:39:19 -08:00
|
|
|
bool atClusterStart = aShapedWord->IsClusterStart(offset);
|
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)
|
|
|
|
{
|
2011-12-06 04:39:19 -08:00
|
|
|
aShapedWord->SetSimpleGlyph(offset,
|
|
|
|
g.SetSimpleGlyph(advanceAppUnits, glyph));
|
2010-03-15 02:34:25 -07:00
|
|
|
} else {
|
2011-12-06 04:39:19 -08:00
|
|
|
gfxShapedWord::DetailedGlyph details;
|
2010-03-15 02:34:25 -07:00
|
|
|
details.mGlyphID = glyph;
|
|
|
|
details.mAdvance = advanceAppUnits;
|
|
|
|
details.mXOffset = 0;
|
|
|
|
details.mYOffset = 0;
|
2011-12-06 04:39:19 -08:00
|
|
|
aShapedWord->SetGlyphs(offset,
|
|
|
|
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
|
|
|
}
|