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
|
2013-01-04 22:35:37 +04:00
|
|
|
gfxGDIShaper::ShapeText(gfxContext *aContext,
|
|
|
|
const PRUnichar *aText,
|
|
|
|
uint32_t aOffset,
|
|
|
|
uint32_t aLength,
|
|
|
|
int32_t aScript,
|
|
|
|
gfxShapedText *aShapedText)
|
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
|
|
|
|
2013-01-04 22:35:37 +04:00
|
|
|
uint32_t length = aLength;
|
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();
|
|
|
|
|
2013-01-04 22:35:37 +04:00
|
|
|
DWORD ret = ::GetGlyphIndicesW(dc, aText, 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;
|
2013-01-04 22:35:37 +04:00
|
|
|
gfxTextRun::CompressedGlyph *charGlyphs =
|
|
|
|
aShapedText->GetCharacterGlyphs();
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t i;
|
|
|
|
int32_t lastWidth = 0;
|
2013-02-20 01:46:27 +04:00
|
|
|
int32_t appUnitsPerDevPixel = aShapedText->GetAppUnitsPerDevUnit();
|
2011-12-06 16:39:19 +04:00
|
|
|
for (i = 0; i < length; ++i) {
|
2013-01-04 22:35:37 +04:00
|
|
|
uint32_t offset = aOffset + i;
|
2012-08-22 19:56:38 +04:00
|
|
|
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];
|
2013-01-04 22:35:37 +04:00
|
|
|
NS_ASSERTION(!gfxFontGroup::IsInvalidChar(aText[i]),
|
2010-03-15 12:34:25 +03:00
|
|
|
"Invalid character detected!");
|
2013-01-04 22:35:37 +04:00
|
|
|
bool atClusterStart = charGlyphs[offset].IsClusterStart();
|
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)
|
|
|
|
{
|
2013-01-04 22:35:37 +04:00
|
|
|
charGlyphs[offset].SetSimpleGlyph(advanceAppUnits, glyph);
|
2010-03-15 12:34:25 +03:00
|
|
|
} else {
|
2013-01-04 22:35:37 +04:00
|
|
|
gfxShapedText::DetailedGlyph details;
|
2010-03-15 12:34:25 +03:00
|
|
|
details.mGlyphID = glyph;
|
|
|
|
details.mAdvance = advanceAppUnits;
|
|
|
|
details.mXOffset = 0;
|
|
|
|
details.mYOffset = 0;
|
2013-01-04 22:35:37 +04:00
|
|
|
aShapedText->SetGlyphs(offset,
|
2011-12-06 16:39:19 +04:00
|
|
|
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
|
|
|
}
|