| 75 | } |
| 76 | |
| 77 | bool GeometricPath::visit(const Byte* data, size_t size, double width, double height, GeometricPathVisitor& visitor) { |
| 78 | auto it = GeometricPath::iterator(data, size); |
| 79 | |
| 80 | if (!it.readExtent()) { |
| 81 | return false; |
| 82 | } |
| 83 | |
| 84 | auto extentWidth = it.getValue(0); |
| 85 | auto extentHeight = it.getValue(1); |
| 86 | |
| 87 | if (extentWidth <= 0 || extentHeight <= 0) { |
| 88 | return false; |
| 89 | } |
| 90 | |
| 91 | double xRatio = width / extentWidth; |
| 92 | double yRatio = height / extentHeight; |
| 93 | |
| 94 | switch (static_cast<GeometricPathScaleType>(it.getValue(2))) { |
| 95 | case GeometricPathScaleType::FILL: |
| 96 | // Default behavior |
| 97 | break; |
| 98 | case GeometricPathScaleType::CONTAIN: { |
| 99 | auto minRatio = std::min(xRatio, yRatio); |
| 100 | xRatio = minRatio; |
| 101 | yRatio = minRatio; |
| 102 | } break; |
| 103 | case GeometricPathScaleType::COVER: { |
| 104 | auto maxRatio = std::max(xRatio, yRatio); |
| 105 | xRatio = maxRatio; |
| 106 | yRatio = maxRatio; |
| 107 | } break; |
| 108 | case GeometricPathScaleType::NONE: |
| 109 | xRatio = 1.0; |
| 110 | yRatio = 1.0; |
| 111 | break; |
| 112 | default: |
| 113 | // Invalid scale type |
| 114 | return false; |
| 115 | } |
| 116 | |
| 117 | auto xOffset = (width - (extentWidth * xRatio)) / 2.0; |
| 118 | auto yOffset = (height - (extentHeight * yRatio)) / 2.0; |
| 119 | |
| 120 | while (it.hasNext()) { |
| 121 | if (!it.next()) { |
| 122 | return false; |
| 123 | } |
| 124 | |
| 125 | switch (it.getComponentType()) { |
| 126 | case GeometricPathComponentTypeMove: |
| 127 | visitor.moveTo(it.getValue(0) * xRatio + xOffset, it.getValue(1) * yRatio + yOffset); |
| 128 | break; |
| 129 | case GeometricPathComponentTypeLine: |
| 130 | visitor.lineTo(it.getValue(0) * xRatio + xOffset, it.getValue(1) * yRatio + yOffset); |
| 131 | break; |
| 132 | case GeometricPathComponentTypeQuad: |
| 133 | visitor.quadTo(it.getValue(0) * xRatio + xOffset, |
| 134 | it.getValue(1) * yRatio + yOffset, |
nothing calls this directly
no test coverage detected