Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
19 / 19
100.00% covered (success)
100.00%
2 / 2
CRAP
100.00% covered (success)
100.00%
1 / 1
BlendMode
100.00% covered (success)
100.00%
19 / 19
100.00% covered (success)
100.00%
2 / 2
19
100.00% covered (success)
100.00%
1 / 1
 pdfNativeName
100.00% covered (success)
100.00%
18 / 18
100.00% covered (success)
100.00%
1 / 1
18
 requiresRaster
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3declare(strict_types=1);
4
5namespace Phpdftk\Raster;
6
7/**
8 * CSS Compositing and Blending 1 + 2 blend modes.
9 *
10 * Some modes have direct PDF equivalents (PDF 32000-2 Table 136 —
11 * `Normal`, `Multiply`, `Screen`, `Overlay`, `Darken`, `Lighten`,
12 * `ColorDodge`, `ColorBurn`, `HardLight`, `SoftLight`, `Difference`,
13 * `Exclusion`, `Hue`, `Saturation`, `Color`, `Luminosity`). The
14 * translator emits these as PDF native ExtGState `/BM` values and
15 * never needs to raster.
16 *
17 * The CSS-only modes (`PlusDarker`, `PlusLighter` — Apple Core
18 * Animation legacy still referenced from CSS Compositing 2) require
19 * raster. Phase 4C.2 implements the per-mode pixel math for raster
20 * fallback.
21 *
22 * `name()` returns the CSS keyword exactly as it appears in the
23 * spec (`mix-blend-mode: <name>`). `pdfNativeName()` returns the
24 * PDF `/BM` name, or null if the mode has no direct PDF equivalent
25 * and must be rasterised.
26 */
27enum BlendMode: string
28{
29    case Normal = 'normal';
30    case Multiply = 'multiply';
31    case Screen = 'screen';
32    case Overlay = 'overlay';
33    case Darken = 'darken';
34    case Lighten = 'lighten';
35    case ColorDodge = 'color-dodge';
36    case ColorBurn = 'color-burn';
37    case HardLight = 'hard-light';
38    case SoftLight = 'soft-light';
39    case Difference = 'difference';
40    case Exclusion = 'exclusion';
41    case Hue = 'hue';
42    case Saturation = 'saturation';
43    case Color = 'color';
44    case Luminosity = 'luminosity';
45    /**
46     * CSS Compositing 2 — Apple Core Animation legacy; raster-only.
47     */
48    case PlusDarker = 'plus-darker';
49    /**
50     * CSS Compositing 2 — Apple Core Animation legacy; raster-only.
51     */
52    case PlusLighter = 'plus-lighter';
53
54    /**
55     * PDF 32000-2 Table 136 `/BM` name for this mode, or null if
56     * the mode has no PDF-native form and must be rasterised. The
57     * translator checks this before deciding whether to lift the
58     * subtree into a {@see RasterSurface}.
59     */
60    public function pdfNativeName(): ?string
61    {
62        return match ($this) {
63            self::Normal => 'Normal',
64            self::Multiply => 'Multiply',
65            self::Screen => 'Screen',
66            self::Overlay => 'Overlay',
67            self::Darken => 'Darken',
68            self::Lighten => 'Lighten',
69            self::ColorDodge => 'ColorDodge',
70            self::ColorBurn => 'ColorBurn',
71            self::HardLight => 'HardLight',
72            self::SoftLight => 'SoftLight',
73            self::Difference => 'Difference',
74            self::Exclusion => 'Exclusion',
75            self::Hue => 'Hue',
76            self::Saturation => 'Saturation',
77            self::Color => 'Color',
78            self::Luminosity => 'Luminosity',
79            self::PlusDarker, self::PlusLighter => null,
80        };
81    }
82
83    /**
84     * True when the translator must rasterise the subtree to apply
85     * this mode. Equivalent to `pdfNativeName() === null`.
86     */
87    public function requiresRaster(): bool
88    {
89        return $this->pdfNativeName() === null;
90    }
91}