LCOV - code coverage report
Current view: top level - gfx/skia/skia/src/core - SkDrawProcs.h (source / functions) Hit Total Coverage
Test: output.info Lines: 7 23 30.4 %
Date: 2017-07-14 16:53:18 Functions: 1 3 33.3 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*
       2             :  * Copyright 2011 Google Inc.
       3             :  *
       4             :  * Use of this source code is governed by a BSD-style license that can be
       5             :  * found in the LICENSE file.
       6             :  */
       7             : 
       8             : #ifndef SkDrawProcs_DEFINED
       9             : #define SkDrawProcs_DEFINED
      10             : 
      11             : #include "SkDraw.h"
      12             : #include "SkGlyph.h"
      13             : 
      14             : bool SkDrawTreatAAStrokeAsHairline(SkScalar strokeWidth, const SkMatrix&,
      15             :                                    SkScalar* coverage);
      16             : 
      17             : /**
      18             :  *  If the current paint is set to stroke and the stroke-width when applied to
      19             :  *  the matrix is <= 1.0, then this returns true, and sets coverage (simulating
      20             :  *  a stroke by drawing a hairline with partial coverage). If any of these
      21             :  *  conditions are false, then this returns false and coverage is ignored.
      22             :  */
      23          74 : inline bool SkDrawTreatAsHairline(const SkPaint& paint, const SkMatrix& matrix,
      24             :                                   SkScalar* coverage) {
      25          74 :     if (SkPaint::kStroke_Style != paint.getStyle()) {
      26          59 :         return false;
      27             :     }
      28             : 
      29          15 :     SkScalar strokeWidth = paint.getStrokeWidth();
      30          15 :     if (0 == strokeWidth) {
      31           0 :         *coverage = SK_Scalar1;
      32           0 :         return true;
      33             :     }
      34             : 
      35          15 :     if (!paint.isAntiAlias()) {
      36           0 :         return false;
      37             :     }
      38             : 
      39          15 :     return SkDrawTreatAAStrokeAsHairline(strokeWidth, matrix, coverage);
      40             : }
      41             : 
      42             : class SkTextAlignProc {
      43             : public:
      44           0 :     SkTextAlignProc(SkPaint::Align align)
      45           0 :         : fAlign(align) {
      46           0 :     }
      47             : 
      48             :     // Returns the glyph position, which may be rounded or not by the caller
      49             :     //   e.g. subpixel doesn't round.
      50           0 :     void operator()(const SkPoint& loc, const SkGlyph& glyph, SkPoint* dst) {
      51           0 :         if (SkPaint::kLeft_Align == fAlign) {
      52           0 :             dst->set(loc.fX, loc.fY);
      53           0 :         } else if (SkPaint::kCenter_Align == fAlign) {
      54           0 :             dst->set(loc.fX - SkFloatToScalar(glyph.fAdvanceX) / 2,
      55           0 :                      loc.fY - SkFloatToScalar(glyph.fAdvanceY) / 2);
      56             :         } else {
      57           0 :             SkASSERT(SkPaint::kRight_Align == fAlign);
      58           0 :             dst->set(loc.fX - SkFloatToScalar(glyph.fAdvanceX),
      59           0 :                      loc.fY - SkFloatToScalar(glyph.fAdvanceY));
      60             :         }
      61           0 :     }
      62             : private:
      63             :     const SkPaint::Align fAlign;
      64             : };
      65             : 
      66             : #endif

Generated by: LCOV version 1.13