gfx/thebes/gfxGDIShaper.cpp

Tue, 06 Jan 2015 21:39:09 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Tue, 06 Jan 2015 21:39:09 +0100
branch
TOR_BUG_9701
changeset 8
97036ab72558
permissions
-rw-r--r--

Conditionally force memory storage according to privacy.thirdparty.isolate;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.

michael@0 1 /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*-
michael@0 2 * This Source Code Form is subject to the terms of the Mozilla Public
michael@0 3 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 5
michael@0 6 //#define FORCE_PR_LOG
michael@0 7
michael@0 8 #include "gfxGDIShaper.h"
michael@0 9
michael@0 10 /**********************************************************************
michael@0 11 *
michael@0 12 * class gfxGDIShaper
michael@0 13 *
michael@0 14 **********************************************************************/
michael@0 15
michael@0 16 bool
michael@0 17 gfxGDIShaper::ShapeText(gfxContext *aContext,
michael@0 18 const char16_t *aText,
michael@0 19 uint32_t aOffset,
michael@0 20 uint32_t aLength,
michael@0 21 int32_t aScript,
michael@0 22 gfxShapedText *aShapedText)
michael@0 23 {
michael@0 24 DCFromContext dc(aContext);
michael@0 25 AutoSelectFont selectFont(dc, static_cast<gfxGDIFont*>(mFont)->GetHFONT());
michael@0 26
michael@0 27 uint32_t length = aLength;
michael@0 28 AutoFallibleTArray<WORD,500> glyphArray;
michael@0 29 if (!glyphArray.SetLength(length)) {
michael@0 30 return false;
michael@0 31 }
michael@0 32 WORD *glyphs = glyphArray.Elements();
michael@0 33
michael@0 34 DWORD ret = ::GetGlyphIndicesW(dc, char16ptr_t(aText), length,
michael@0 35 glyphs, GGI_MARK_NONEXISTING_GLYPHS);
michael@0 36 if (ret == GDI_ERROR) {
michael@0 37 return false;
michael@0 38 }
michael@0 39
michael@0 40 for (int k = 0; k < length; k++) {
michael@0 41 if (glyphs[k] == 0xFFFF)
michael@0 42 return false;
michael@0 43 }
michael@0 44
michael@0 45 SIZE size;
michael@0 46 AutoFallibleTArray<int,500> partialWidthArray;
michael@0 47 if (!partialWidthArray.SetLength(length)) {
michael@0 48 return false;
michael@0 49 }
michael@0 50
michael@0 51 BOOL success = ::GetTextExtentExPointI(dc,
michael@0 52 glyphs,
michael@0 53 length,
michael@0 54 INT_MAX,
michael@0 55 nullptr,
michael@0 56 partialWidthArray.Elements(),
michael@0 57 &size);
michael@0 58 if (!success) {
michael@0 59 return false;
michael@0 60 }
michael@0 61
michael@0 62 gfxTextRun::CompressedGlyph g;
michael@0 63 gfxTextRun::CompressedGlyph *charGlyphs =
michael@0 64 aShapedText->GetCharacterGlyphs();
michael@0 65 uint32_t i;
michael@0 66 int32_t lastWidth = 0;
michael@0 67 int32_t appUnitsPerDevPixel = aShapedText->GetAppUnitsPerDevUnit();
michael@0 68 for (i = 0; i < length; ++i) {
michael@0 69 uint32_t offset = aOffset + i;
michael@0 70 int32_t advancePixels = partialWidthArray[i] - lastWidth;
michael@0 71 lastWidth = partialWidthArray[i];
michael@0 72 int32_t advanceAppUnits = advancePixels * appUnitsPerDevPixel;
michael@0 73 WCHAR glyph = glyphs[i];
michael@0 74 NS_ASSERTION(!gfxFontGroup::IsInvalidChar(aText[i]),
michael@0 75 "Invalid character detected!");
michael@0 76 bool atClusterStart = charGlyphs[offset].IsClusterStart();
michael@0 77 if (advanceAppUnits >= 0 &&
michael@0 78 gfxShapedWord::CompressedGlyph::IsSimpleAdvance(advanceAppUnits) &&
michael@0 79 gfxShapedWord::CompressedGlyph::IsSimpleGlyphID(glyph) &&
michael@0 80 atClusterStart)
michael@0 81 {
michael@0 82 charGlyphs[offset].SetSimpleGlyph(advanceAppUnits, glyph);
michael@0 83 } else {
michael@0 84 gfxShapedText::DetailedGlyph details;
michael@0 85 details.mGlyphID = glyph;
michael@0 86 details.mAdvance = advanceAppUnits;
michael@0 87 details.mXOffset = 0;
michael@0 88 details.mYOffset = 0;
michael@0 89 aShapedText->SetGlyphs(offset,
michael@0 90 g.SetComplex(atClusterStart, true, 1),
michael@0 91 &details);
michael@0 92 }
michael@0 93 }
michael@0 94
michael@0 95 return true;
michael@0 96 }

mercurial