Flutter Engine
The Flutter Engine
Functions
SkGlyph.cpp File Reference
#include "src/core/SkGlyph.h"
#include "include/core/SkCanvas.h"
#include "include/core/SkData.h"
#include "include/core/SkDrawable.h"
#include "include/core/SkPicture.h"
#include "include/core/SkScalar.h"
#include "include/core/SkSerialProcs.h"
#include "include/core/SkSpan.h"
#include "include/private/base/SkFloatingPoint.h"
#include "include/private/base/SkTFitsIn.h"
#include "include/private/base/SkTo.h"
#include "src/base/SkArenaAlloc.h"
#include "src/base/SkBezierCurves.h"
#include "src/core/SkReadBuffer.h"
#include "src/core/SkScalerContext.h"
#include "src/core/SkWriteBuffer.h"
#include "src/text/StrikeForGPU.h"
#include <cstring>
#include <optional>
#include <tuple>
#include <utility>

Go to the source code of this file.

Functions

static size_t bits_to_bytes (size_t bits)
 
static size_t format_alignment (SkMask::Format format)
 
static size_t format_rowbytes (int width, SkMask::Format format)
 
static std::tuple< SkScalar, SkScalarcalculate_path_gap (SkScalar topOffset, SkScalar bottomOffset, const SkPath &path)
 

Function Documentation

◆ bits_to_bytes()

static size_t bits_to_bytes ( size_t  bits)
static

Definition at line 146 of file SkGlyph.cpp.

146 {
147 return (bits + 7) >> 3;
148}

◆ calculate_path_gap()

static std::tuple< SkScalar, SkScalar > calculate_path_gap ( SkScalar  topOffset,
SkScalar  bottomOffset,
const SkPath path 
)
static

Definition at line 440 of file SkGlyph.cpp.

441 {
442
443 // Left and Right of an ever expanding gap around the path.
446
447 auto expandGap = [&left, &right](SkScalar v) {
448 left = std::min(left, v);
449 right = std::max(right, v);
450 };
451
452 // Handle all the different verbs for the path.
453 SkPoint pts[4];
454 auto addLine = [&](SkScalar offset) {
455 SkScalar t = sk_ieee_float_divide(offset - pts[0].fY, pts[1].fY - pts[0].fY);
456 if (0 <= t && t < 1) { // this handles divide by zero above
457 expandGap(pts[0].fX + t * (pts[1].fX - pts[0].fX));
458 }
459 };
460
461 auto addQuad = [&](SkScalar offset) {
462 SkScalar intersectionStorage[2];
464 SkSpan(pts, 3), offset, intersectionStorage);
465 for (SkScalar x : intersections) {
466 expandGap(x);
467 }
468 };
469
470 auto addCubic = [&](SkScalar offset) {
471 float intersectionStorage[3];
473 SkSpan{pts, 4}, offset, intersectionStorage);
474
475 for(double intersection : intersections) {
476 expandGap(intersection);
477 }
478 };
479
480 // Handle when a verb's points are in the gap between top and bottom.
481 auto addPts = [&expandGap, &pts, topOffset, bottomOffset](int ptCount) {
482 for (int i = 0; i < ptCount; ++i) {
483 if (topOffset < pts[i].fY && pts[i].fY < bottomOffset) {
484 expandGap(pts[i].fX);
485 }
486 }
487 };
488
489 SkPath::Iter iter(path, false);
490 SkPath::Verb verb;
491 while (SkPath::kDone_Verb != (verb = iter.next(pts))) {
492 switch (verb) {
493 case SkPath::kMove_Verb: {
494 break;
495 }
496 case SkPath::kLine_Verb: {
497 auto [lineTop, lineBottom] = std::minmax({pts[0].fY, pts[1].fY});
498
499 // The y-coordinates of the points intersect the top and bottom offsets.
500 if (topOffset <= lineBottom && lineTop <= bottomOffset) {
501 addLine(topOffset);
502 addLine(bottomOffset);
503 addPts(2);
504 }
505 break;
506 }
507 case SkPath::kQuad_Verb: {
508 auto [quadTop, quadBottom] = std::minmax({pts[0].fY, pts[1].fY, pts[2].fY});
509
510 // The y-coordinates of the points intersect the top and bottom offsets.
511 if (topOffset <= quadBottom && quadTop <= bottomOffset) {
512 addQuad(topOffset);
513 addQuad(bottomOffset);
514 addPts(3);
515 }
516 break;
517 }
518 case SkPath::kConic_Verb: {
519 SkDEBUGFAIL("There should be no conic primitives in glyph outlines.");
520 break;
521 }
522 case SkPath::kCubic_Verb: {
523 auto [cubicTop, cubicBottom] =
524 std::minmax({pts[0].fY, pts[1].fY, pts[2].fY, pts[3].fY});
525
526 // The y-coordinates of the points intersect the top and bottom offsets.
527 if (topOffset <= cubicBottom && cubicTop <= bottomOffset) {
528 addCubic(topOffset);
529 addCubic(bottomOffset);
530 addPts(4);
531 }
532 break;
533 }
534 case SkPath::kClose_Verb: {
535 break;
536 }
537 default: {
538 SkDEBUGFAIL("Unknown path verb generating glyph underline.");
539 break;
540 }
541 }
542 }
543
544 return std::tie(left, right);
545}
#define SkDEBUGFAIL(message)
Definition: SkAssert.h:118
static constexpr float sk_ieee_float_divide(float numer, float denom)
static bool left(const SkPoint &p0, const SkPoint &p1)
static bool right(const SkPoint &p0, const SkPoint &p1)
#define SK_ScalarMin
Definition: SkScalar.h:25
#define SK_ScalarMax
Definition: SkScalar.h:24
SkSpan(Container &&) -> SkSpan< std::remove_pointer_t< decltype(std::data(std::declval< Container >()))> >
static SkSpan< const float > IntersectWithHorizontalLine(SkSpan< const SkPoint > controlPoints, float yIntercept, float intersectionStorage[3])
static SkSpan< const float > IntersectWithHorizontalLine(SkSpan< const SkPoint > controlPoints, float yIntercept, float intersectionStorage[2])
@ kClose_Verb
Definition: SkPath.h:1471
@ kMove_Verb
Definition: SkPath.h:1466
@ kConic_Verb
Definition: SkPath.h:1469
@ kDone_Verb
Definition: SkPath.h:1472
@ kCubic_Verb
Definition: SkPath.h:1470
@ kQuad_Verb
Definition: SkPath.h:1468
@ kLine_Verb
Definition: SkPath.h:1467
float SkScalar
Definition: extension.cpp:12
static float max(float r, float g, float b)
Definition: hsl.cpp:49
static float min(float r, float g, float b)
Definition: hsl.cpp:48
double x
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir path
Definition: switches.h:57
SeparatedVector2 offset

◆ format_alignment()

static size_t format_alignment ( SkMask::Format  format)
static

Definition at line 150 of file SkGlyph.cpp.

150 {
151 switch (format) {
156 return alignof(uint8_t);
158 return alignof(uint32_t);
160 return alignof(uint16_t);
161 default:
162 SK_ABORT("Unknown mask format.");
163 break;
164 }
165 return 0;
166}
#define SK_ABORT(message,...)
Definition: SkAssert.h:70
uint32_t uint32_t * format
@ k3D_Format
3 8bit per pixl planes: alpha, mul, add
Definition: SkMask.h:29
@ kA8_Format
8bits per pixel mask (e.g. antialiasing)
Definition: SkMask.h:28
@ kLCD16_Format
565 alpha for r/g/b
Definition: SkMask.h:31
@ kARGB32_Format
SkPMColor.
Definition: SkMask.h:30
@ kSDF_Format
8bits representing signed distance field
Definition: SkMask.h:32
@ kBW_Format
1bit per pixel mask (e.g. monochrome)
Definition: SkMask.h:27

◆ format_rowbytes()

static size_t format_rowbytes ( int  width,
SkMask::Format  format 
)
static

Definition at line 168 of file SkGlyph.cpp.

168 {
171}
static size_t format_alignment(SkMask::Format format)
Definition: SkGlyph.cpp:150
static size_t bits_to_bytes(size_t bits)
Definition: SkGlyph.cpp:146
int32_t width