Sat, 03 Jan 2015 20:18:00 +0100
Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.
michael@0 | 1 | /* |
michael@0 | 2 | * Copyright 2013 Google Inc. |
michael@0 | 3 | * |
michael@0 | 4 | * Use of this source code is governed by a BSD-style license that can be |
michael@0 | 5 | * found in the LICENSE file. |
michael@0 | 6 | */ |
michael@0 | 7 | |
michael@0 | 8 | #include "SkGScalerContext.h" |
michael@0 | 9 | #include "SkGlyph.h" |
michael@0 | 10 | #include "SkPath.h" |
michael@0 | 11 | #include "SkCanvas.h" |
michael@0 | 12 | |
michael@0 | 13 | class SkGScalerContext : public SkScalerContext { |
michael@0 | 14 | public: |
michael@0 | 15 | SkGScalerContext(SkGTypeface*, const SkDescriptor*); |
michael@0 | 16 | virtual ~SkGScalerContext(); |
michael@0 | 17 | |
michael@0 | 18 | protected: |
michael@0 | 19 | virtual unsigned generateGlyphCount() SK_OVERRIDE; |
michael@0 | 20 | virtual uint16_t generateCharToGlyph(SkUnichar) SK_OVERRIDE; |
michael@0 | 21 | virtual void generateAdvance(SkGlyph*) SK_OVERRIDE; |
michael@0 | 22 | virtual void generateMetrics(SkGlyph*) SK_OVERRIDE; |
michael@0 | 23 | virtual void generateImage(const SkGlyph&) SK_OVERRIDE; |
michael@0 | 24 | virtual void generatePath(const SkGlyph&, SkPath*) SK_OVERRIDE; |
michael@0 | 25 | virtual void generateFontMetrics(SkPaint::FontMetrics* mX, |
michael@0 | 26 | SkPaint::FontMetrics* mY) SK_OVERRIDE; |
michael@0 | 27 | |
michael@0 | 28 | private: |
michael@0 | 29 | SkGTypeface* fFace; |
michael@0 | 30 | SkScalerContext* fProxy; |
michael@0 | 31 | SkMatrix fMatrix; |
michael@0 | 32 | }; |
michael@0 | 33 | |
michael@0 | 34 | #define STD_SIZE 1 |
michael@0 | 35 | |
michael@0 | 36 | #include "SkDescriptor.h" |
michael@0 | 37 | |
michael@0 | 38 | SkGScalerContext::SkGScalerContext(SkGTypeface* face, const SkDescriptor* desc) |
michael@0 | 39 | : SkScalerContext(face, desc) |
michael@0 | 40 | , fFace(face) |
michael@0 | 41 | { |
michael@0 | 42 | |
michael@0 | 43 | size_t descSize = SkDescriptor::ComputeOverhead(1) + sizeof(SkScalerContext::Rec); |
michael@0 | 44 | SkAutoDescriptor ad(descSize); |
michael@0 | 45 | SkDescriptor* newDesc = ad.getDesc(); |
michael@0 | 46 | |
michael@0 | 47 | newDesc->init(); |
michael@0 | 48 | void* entry = newDesc->addEntry(kRec_SkDescriptorTag, |
michael@0 | 49 | sizeof(SkScalerContext::Rec), &fRec); |
michael@0 | 50 | { |
michael@0 | 51 | SkScalerContext::Rec* rec = (SkScalerContext::Rec*)entry; |
michael@0 | 52 | rec->fTextSize = STD_SIZE; |
michael@0 | 53 | rec->fPreScaleX = SK_Scalar1; |
michael@0 | 54 | rec->fPreSkewX = 0; |
michael@0 | 55 | rec->fPost2x2[0][0] = rec->fPost2x2[1][1] = SK_Scalar1; |
michael@0 | 56 | rec->fPost2x2[1][0] = rec->fPost2x2[0][1] = 0; |
michael@0 | 57 | } |
michael@0 | 58 | SkASSERT(descSize == newDesc->getLength()); |
michael@0 | 59 | newDesc->computeChecksum(); |
michael@0 | 60 | |
michael@0 | 61 | fProxy = face->proxy()->createScalerContext(newDesc); |
michael@0 | 62 | |
michael@0 | 63 | fRec.getSingleMatrix(&fMatrix); |
michael@0 | 64 | fMatrix.preScale(SK_Scalar1 / STD_SIZE, SK_Scalar1 / STD_SIZE); |
michael@0 | 65 | } |
michael@0 | 66 | |
michael@0 | 67 | SkGScalerContext::~SkGScalerContext() { |
michael@0 | 68 | SkDELETE(fProxy); |
michael@0 | 69 | } |
michael@0 | 70 | |
michael@0 | 71 | unsigned SkGScalerContext::generateGlyphCount() { |
michael@0 | 72 | return fProxy->getGlyphCount(); |
michael@0 | 73 | } |
michael@0 | 74 | |
michael@0 | 75 | uint16_t SkGScalerContext::generateCharToGlyph(SkUnichar uni) { |
michael@0 | 76 | return fProxy->charToGlyphID(uni); |
michael@0 | 77 | } |
michael@0 | 78 | |
michael@0 | 79 | void SkGScalerContext::generateAdvance(SkGlyph* glyph) { |
michael@0 | 80 | fProxy->getAdvance(glyph); |
michael@0 | 81 | |
michael@0 | 82 | SkVector advance; |
michael@0 | 83 | fMatrix.mapXY(SkFixedToScalar(glyph->fAdvanceX), |
michael@0 | 84 | SkFixedToScalar(glyph->fAdvanceY), &advance); |
michael@0 | 85 | glyph->fAdvanceX = SkScalarToFixed(advance.fX); |
michael@0 | 86 | glyph->fAdvanceY = SkScalarToFixed(advance.fY); |
michael@0 | 87 | } |
michael@0 | 88 | |
michael@0 | 89 | void SkGScalerContext::generateMetrics(SkGlyph* glyph) { |
michael@0 | 90 | fProxy->getMetrics(glyph); |
michael@0 | 91 | |
michael@0 | 92 | SkVector advance; |
michael@0 | 93 | fMatrix.mapXY(SkFixedToScalar(glyph->fAdvanceX), |
michael@0 | 94 | SkFixedToScalar(glyph->fAdvanceY), &advance); |
michael@0 | 95 | glyph->fAdvanceX = SkScalarToFixed(advance.fX); |
michael@0 | 96 | glyph->fAdvanceY = SkScalarToFixed(advance.fY); |
michael@0 | 97 | |
michael@0 | 98 | SkPath path; |
michael@0 | 99 | fProxy->getPath(*glyph, &path); |
michael@0 | 100 | path.transform(fMatrix); |
michael@0 | 101 | |
michael@0 | 102 | SkRect storage; |
michael@0 | 103 | const SkPaint& paint = fFace->paint(); |
michael@0 | 104 | const SkRect& newBounds = paint.doComputeFastBounds(path.getBounds(), |
michael@0 | 105 | &storage, |
michael@0 | 106 | SkPaint::kFill_Style); |
michael@0 | 107 | SkIRect ibounds; |
michael@0 | 108 | newBounds.roundOut(&ibounds); |
michael@0 | 109 | glyph->fLeft = ibounds.fLeft; |
michael@0 | 110 | glyph->fTop = ibounds.fTop; |
michael@0 | 111 | glyph->fWidth = ibounds.width(); |
michael@0 | 112 | glyph->fHeight = ibounds.height(); |
michael@0 | 113 | glyph->fMaskFormat = SkMask::kARGB32_Format; |
michael@0 | 114 | } |
michael@0 | 115 | |
michael@0 | 116 | void SkGScalerContext::generateImage(const SkGlyph& glyph) { |
michael@0 | 117 | if (SkMask::kARGB32_Format == glyph.fMaskFormat) { |
michael@0 | 118 | SkPath path; |
michael@0 | 119 | fProxy->getPath(glyph, &path); |
michael@0 | 120 | |
michael@0 | 121 | SkBitmap bm; |
michael@0 | 122 | bm.setConfig(SkBitmap::kARGB_8888_Config, glyph.fWidth, glyph.fHeight, |
michael@0 | 123 | glyph.rowBytes()); |
michael@0 | 124 | bm.setPixels(glyph.fImage); |
michael@0 | 125 | bm.eraseColor(0); |
michael@0 | 126 | |
michael@0 | 127 | SkCanvas canvas(bm); |
michael@0 | 128 | canvas.translate(-SkIntToScalar(glyph.fLeft), |
michael@0 | 129 | -SkIntToScalar(glyph.fTop)); |
michael@0 | 130 | canvas.concat(fMatrix); |
michael@0 | 131 | canvas.drawPath(path, fFace->paint()); |
michael@0 | 132 | } else { |
michael@0 | 133 | fProxy->getImage(glyph); |
michael@0 | 134 | } |
michael@0 | 135 | } |
michael@0 | 136 | |
michael@0 | 137 | void SkGScalerContext::generatePath(const SkGlyph& glyph, SkPath* path) { |
michael@0 | 138 | fProxy->getPath(glyph, path); |
michael@0 | 139 | path->transform(fMatrix); |
michael@0 | 140 | } |
michael@0 | 141 | |
michael@0 | 142 | void SkGScalerContext::generateFontMetrics(SkPaint::FontMetrics*, |
michael@0 | 143 | SkPaint::FontMetrics* metrics) { |
michael@0 | 144 | fProxy->getFontMetrics(metrics); |
michael@0 | 145 | if (metrics) { |
michael@0 | 146 | SkScalar scale = fMatrix.getScaleY(); |
michael@0 | 147 | metrics->fTop = SkScalarMul(metrics->fTop, scale); |
michael@0 | 148 | metrics->fAscent = SkScalarMul(metrics->fAscent, scale); |
michael@0 | 149 | metrics->fDescent = SkScalarMul(metrics->fDescent, scale); |
michael@0 | 150 | metrics->fBottom = SkScalarMul(metrics->fBottom, scale); |
michael@0 | 151 | metrics->fLeading = SkScalarMul(metrics->fLeading, scale); |
michael@0 | 152 | metrics->fAvgCharWidth = SkScalarMul(metrics->fAvgCharWidth, scale); |
michael@0 | 153 | metrics->fXMin = SkScalarMul(metrics->fXMin, scale); |
michael@0 | 154 | metrics->fXMax = SkScalarMul(metrics->fXMax, scale); |
michael@0 | 155 | metrics->fXHeight = SkScalarMul(metrics->fXHeight, scale); |
michael@0 | 156 | } |
michael@0 | 157 | } |
michael@0 | 158 | |
michael@0 | 159 | /////////////////////////////////////////////////////////////////////////////// |
michael@0 | 160 | |
michael@0 | 161 | #include "SkTypefaceCache.h" |
michael@0 | 162 | |
michael@0 | 163 | SkGTypeface::SkGTypeface(SkTypeface* proxy, const SkPaint& paint) |
michael@0 | 164 | : SkTypeface(proxy->style(), SkTypefaceCache::NewFontID(), false) |
michael@0 | 165 | , fProxy(SkRef(proxy)) |
michael@0 | 166 | , fPaint(paint) {} |
michael@0 | 167 | |
michael@0 | 168 | SkGTypeface::~SkGTypeface() { |
michael@0 | 169 | fProxy->unref(); |
michael@0 | 170 | } |
michael@0 | 171 | |
michael@0 | 172 | SkScalerContext* SkGTypeface::onCreateScalerContext( |
michael@0 | 173 | const SkDescriptor* desc) const { |
michael@0 | 174 | return SkNEW_ARGS(SkGScalerContext, (const_cast<SkGTypeface*>(this), desc)); |
michael@0 | 175 | } |
michael@0 | 176 | |
michael@0 | 177 | void SkGTypeface::onFilterRec(SkScalerContextRec* rec) const { |
michael@0 | 178 | fProxy->filterRec(rec); |
michael@0 | 179 | rec->setHinting(SkPaint::kNo_Hinting); |
michael@0 | 180 | rec->fMaskFormat = SkMask::kARGB32_Format; |
michael@0 | 181 | } |
michael@0 | 182 | |
michael@0 | 183 | SkAdvancedTypefaceMetrics* SkGTypeface::onGetAdvancedTypefaceMetrics( |
michael@0 | 184 | SkAdvancedTypefaceMetrics::PerGlyphInfo info, |
michael@0 | 185 | const uint32_t* glyphIDs, |
michael@0 | 186 | uint32_t glyphIDsCount) const { |
michael@0 | 187 | return fProxy->getAdvancedTypefaceMetrics(info, glyphIDs, glyphIDsCount); |
michael@0 | 188 | } |
michael@0 | 189 | |
michael@0 | 190 | SkStream* SkGTypeface::onOpenStream(int* ttcIndex) const { |
michael@0 | 191 | return fProxy->openStream(ttcIndex); |
michael@0 | 192 | } |
michael@0 | 193 | |
michael@0 | 194 | void SkGTypeface::onGetFontDescriptor(SkFontDescriptor* desc, |
michael@0 | 195 | bool* isLocal) const { |
michael@0 | 196 | fProxy->getFontDescriptor(desc, isLocal); |
michael@0 | 197 | } |
michael@0 | 198 | |
michael@0 | 199 | int SkGTypeface::onCharsToGlyphs(const void* chars, Encoding encoding, |
michael@0 | 200 | uint16_t glyphs[], int glyphCount) const { |
michael@0 | 201 | return fProxy->charsToGlyphs(chars, encoding, glyphs, glyphCount); |
michael@0 | 202 | } |
michael@0 | 203 | |
michael@0 | 204 | int SkGTypeface::onCountGlyphs() const { |
michael@0 | 205 | return fProxy->countGlyphs(); |
michael@0 | 206 | } |
michael@0 | 207 | |
michael@0 | 208 | int SkGTypeface::onGetUPEM() const { |
michael@0 | 209 | return fProxy->getUnitsPerEm(); |
michael@0 | 210 | } |
michael@0 | 211 | |
michael@0 | 212 | SkTypeface::LocalizedStrings* SkGTypeface::onCreateFamilyNameIterator() const { |
michael@0 | 213 | return fProxy->createFamilyNameIterator(); |
michael@0 | 214 | } |
michael@0 | 215 | |
michael@0 | 216 | int SkGTypeface::onGetTableTags(SkFontTableTag tags[]) const { |
michael@0 | 217 | return fProxy->getTableTags(tags); |
michael@0 | 218 | } |
michael@0 | 219 | |
michael@0 | 220 | size_t SkGTypeface::onGetTableData(SkFontTableTag tag, size_t offset, |
michael@0 | 221 | size_t length, void* data) const { |
michael@0 | 222 | return fProxy->getTableData(tag, offset, length, data); |
michael@0 | 223 | } |
michael@0 | 224 | |
michael@0 | 225 | /////////////////////////////////////////////////////////////////////////////// |
michael@0 | 226 | |
michael@0 | 227 | #if 0 |
michael@0 | 228 | // under construction -- defining a font purely in terms of skia primitives |
michael@0 | 229 | // ala an SVG-font. |
michael@0 | 230 | class SkGFont : public SkRefCnt { |
michael@0 | 231 | public: |
michael@0 | 232 | virtual ~SkGFont(); |
michael@0 | 233 | |
michael@0 | 234 | int unicharToGlyph(SkUnichar) const; |
michael@0 | 235 | |
michael@0 | 236 | int countGlyphs() const { return fCount; } |
michael@0 | 237 | |
michael@0 | 238 | float getAdvance(int index) const { |
michael@0 | 239 | SkASSERT((unsigned)index < (unsigned)fCount); |
michael@0 | 240 | return fGlyphs[index].fAdvance; |
michael@0 | 241 | } |
michael@0 | 242 | |
michael@0 | 243 | const SkPath& getPath(int index) const { |
michael@0 | 244 | SkASSERT((unsigned)index < (unsigned)fCount); |
michael@0 | 245 | return fGlyphs[index].fPath; |
michael@0 | 246 | } |
michael@0 | 247 | |
michael@0 | 248 | private: |
michael@0 | 249 | struct Glyph { |
michael@0 | 250 | SkUnichar fUni; |
michael@0 | 251 | float fAdvance; |
michael@0 | 252 | SkPath fPath; |
michael@0 | 253 | }; |
michael@0 | 254 | int fCount; |
michael@0 | 255 | Glyph* fGlyphs; |
michael@0 | 256 | |
michael@0 | 257 | friend class SkGFontBuilder; |
michael@0 | 258 | SkGFont(int count, Glyph* array); |
michael@0 | 259 | }; |
michael@0 | 260 | |
michael@0 | 261 | class SkGFontBuilder { |
michael@0 | 262 | public: |
michael@0 | 263 | |
michael@0 | 264 | }; |
michael@0 | 265 | #endif |