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