Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(310)

Side by Side Diff: src/core/SkTypeface.cpp

Issue 676523002: Add SkTypeface::getBounds() (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/core/SkThreadPriv.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2011 The Android Open Source Project 2 * Copyright 2011 The Android Open Source Project
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "SkAdvancedTypefaceMetrics.h" 8 #include "SkAdvancedTypefaceMetrics.h"
9 #include "SkEndian.h" 9 #include "SkEndian.h"
10 #include "SkFontDescriptor.h" 10 #include "SkFontDescriptor.h"
(...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after
271 if (os2table.version.v2.fsType.field.NoSubsetting) { 271 if (os2table.version.v2.fsType.field.NoSubsetting) {
272 result->fFlags = SkTBitOr<SkAdvancedTypefaceMetrics::FontFlags>( 272 result->fFlags = SkTBitOr<SkAdvancedTypefaceMetrics::FontFlags>(
273 result->fFlags, 273 result->fFlags,
274 SkAdvancedTypefaceMetrics::kNotSubsettable_FontFlag); 274 SkAdvancedTypefaceMetrics::kNotSubsettable_FontFlag);
275 } 275 }
276 } 276 }
277 } 277 }
278 return result; 278 return result;
279 } 279 }
280 280
281 ///////////////////////////////////////////////////////////////////////////////
282
283 bool SkTypeface::onGetKerningPairAdjustments(const uint16_t glyphs[], int count, 281 bool SkTypeface::onGetKerningPairAdjustments(const uint16_t glyphs[], int count,
284 int32_t adjustments[]) const { 282 int32_t adjustments[]) const {
285 return false; 283 return false;
286 } 284 }
285
286 ///////////////////////////////////////////////////////////////////////////////
287
288 #include "SkDescriptor.h"
289 #include "SkPaint.h"
290
291 struct SkTypeface::BoundsComputer {
292 const SkTypeface& fTypeface;
293
294 BoundsComputer(const SkTypeface& tf) : fTypeface(tf) {}
295
296 SkRect* operator()() const {
297 SkRect* rect = SkNEW(SkRect);
298 if (!fTypeface.onComputeBounds(rect)) {
299 rect->setEmpty();
300 }
301 return rect;
302 }
303 };
304
305 SkRect SkTypeface::getBounds() const {
306 return *fLazyBounds.get(BoundsComputer(*this));
307 }
308
309 bool SkTypeface::onComputeBounds(SkRect* bounds) const {
310 // we use a big size to ensure lots of significant bits from the scalerconte xt.
311 // then we scale back down to return our final answer (at 1-pt)
312 const SkScalar textSize = 2048;
313 const SkScalar invTextSize = 1 / textSize;
314
315 SkPaint paint;
316 paint.setTypeface(const_cast<SkTypeface*>(this));
317 paint.setTextSize(textSize);
318 paint.setLinearText(true);
319
320 SkScalerContext::Rec rec;
321 SkScalerContext::MakeRec(paint, NULL, NULL, &rec);
322
323 SkAutoDescriptor ad(sizeof(rec) + SkDescriptor::ComputeOverhead(1));
324 SkDescriptor* desc = ad.getDesc();
325 desc->init();
326 desc->addEntry(kRec_SkDescriptorTag, sizeof(rec), &rec);
327
328 SkAutoTDelete<SkScalerContext> ctx(this->createScalerContext(desc, true));
329 if (ctx.get()) {
330 SkPaint::FontMetrics fm;
331 ctx->getFontMetrics(&fm);
332 bounds->set(fm.fXMin * invTextSize, fm.fTop * invTextSize,
333 fm.fXMax * invTextSize, fm.fBottom * invTextSize);
334 return true;
335 }
336 return false;
337 }
338
OLDNEW
« no previous file with comments | « src/core/SkThreadPriv.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698