};
struct FrameInfo {
- FrameInfo(uint32_t frame): _frameNo(frame){}
+ explicit FrameInfo(uint32_t frame): _frameNo(frame){}
uint32_t curFrame() const {return _frameNo;}
private:
uint32_t _frameNo;
}
-LOTRepeaterItem::LOTRepeaterItem(LOTRepeaterData *data) : mData(data)
+LOTRepeaterItem::LOTRepeaterItem(LOTRepeaterData *data) : mRepeaterData(data)
{
- assert(mData->content());
+ assert(mRepeaterData->content());
- mCopies = mData->maxCopies();
+ mCopies = mRepeaterData->maxCopies();
for (int i= 0; i < mCopies; i++) {
- auto content = std::make_unique<LOTContentGroupItem>(mData->content());
+ auto content = std::make_unique<LOTContentGroupItem>(mRepeaterData->content());
content->setParent(this);
mContents.push_back(std::move(content));
}
DirtyFlag newFlag = flag;
- float copies = mData->copies(frameNo);
+ float copies = mRepeaterData->copies(frameNo);
int visibleCopies = int(copies);
if (visibleCopies == 0) {
mHidden = false;
}
- if (!mData->isStatic()) newFlag |= DirtyFlagBit::Matrix;
+ if (!mRepeaterData->isStatic()) newFlag |= DirtyFlagBit::Matrix;
- float offset = mData->offset(frameNo);
- float startOpacity = mData->mTransform.startOpacity(frameNo);
- float endOpacity = mData->mTransform.endOpacity(frameNo);
+ float offset = mRepeaterData->offset(frameNo);
+ float startOpacity = mRepeaterData->mTransform.startOpacity(frameNo);
+ float endOpacity = mRepeaterData->mTransform.endOpacity(frameNo);
newFlag |= DirtyFlagBit::Alpha;
// hide rest of the copies , @TODO find a better solution.
if ( i >= visibleCopies) newAlpha = 0;
- VMatrix result = mData->mTransform.matrix(frameNo, i + offset) * parentMatrix;
+ VMatrix result = mRepeaterData->mTransform.matrix(frameNo, i + offset) * parentMatrix;
mContents[i]->update(frameNo, result, newAlpha, newFlag);
}
}
case CapStyle::Round:
mCNode->mStroke.cap = LOTCapStyle::CapRound;
break;
- default:
- mCNode->mStroke.cap = LOTCapStyle::CapFlat;
- break;
}
switch (mStroke.join) {
class LOTCompItem
{
public:
- LOTCompItem(LOTModel *model);
+ explicit LOTCompItem(LOTModel *model);
static std::unique_ptr<LOTLayerItem> createLayerItem(LOTLayerData *layerData);
bool update(int frameNo);
void resize(const VSize &size);
class LOTClipperItem
{
public:
- LOTClipperItem(VSize size): mSize(size){}
+ explicit LOTClipperItem(VSize size): mSize(size){}
void update(const VMatrix &matrix);
VRle rle();
public:
class LOTCompLayerItem: public LOTLayerItem
{
public:
- LOTCompLayerItem(LOTLayerData *layerData);
+ explicit LOTCompLayerItem(LOTLayerData *layerData);
void renderList(std::vector<VDrawable *> &list)final;
void render(VPainter *painter, const VRle &mask, const VRle &matteRle) final;
void buildLayerNode() final;
class LOTSolidLayerItem: public LOTLayerItem
{
public:
- LOTSolidLayerItem(LOTLayerData *layerData);
+ explicit LOTSolidLayerItem(LOTLayerData *layerData);
void buildLayerNode() final;
protected:
void updateContent() final;
class LOTShapeLayerItem: public LOTLayerItem
{
public:
- LOTShapeLayerItem(LOTLayerData *layerData);
+ explicit LOTShapeLayerItem(LOTLayerData *layerData);
static std::unique_ptr<LOTContentItem> createContentItem(LOTData *contentData);
void renderList(std::vector<VDrawable *> &list)final;
void buildLayerNode() final;
class LOTNullLayerItem: public LOTLayerItem
{
public:
- LOTNullLayerItem(LOTLayerData *layerData);
+ explicit LOTNullLayerItem(LOTLayerData *layerData);
protected:
void updateContent() final;
};
class LOTImageLayerItem: public LOTLayerItem
{
public:
- LOTImageLayerItem(LOTLayerData *layerData);
+ explicit LOTImageLayerItem(LOTLayerData *layerData);
void buildLayerNode() final;
protected:
void updateContent() final;
class LOTMaskItem
{
public:
- LOTMaskItem(LOTMaskData *data): mData(data), mCombinedAlpha(0){}
+ explicit LOTMaskItem(LOTMaskData *data): mData(data){}
void update(int frameNo, const VMatrix &parentMatrix, float parentAlpha, const DirtyFlag &flag);
LOTMaskData::Mode maskMode() const { return mData->mMode;}
VRle rle();
public:
LOTMaskData *mData;
- float mCombinedAlpha;
+ float mCombinedAlpha{0};
VMatrix mCombinedMatrix;
VPath mLocalPath;
VPath mFinalPath;
class LOTLayerMaskItem
{
public:
- LOTLayerMaskItem(LOTLayerData *layerData);
+ explicit LOTLayerMaskItem(LOTLayerData *layerData);
void update(int frameNo, const VMatrix &parentMatrix, float parentAlpha, const DirtyFlag &flag);
bool isStatic() const {return mStatic;}
VRle maskRle(const VRect &clipRect);
class LOTContentGroupItem: public LOTContentItem
{
public:
- LOTContentGroupItem(LOTGroupData *data=nullptr);
+ explicit LOTContentGroupItem(LOTGroupData *data=nullptr);
void addChildren(LOTGroupData *data);
void update(int frameNo, const VMatrix &parentMatrix, float parentAlpha, const DirtyFlag &flag) override;
void applyTrim();
class LOTRectItem: public LOTPathDataItem
{
public:
- LOTRectItem(LOTRectData *data);
+ explicit LOTRectItem(LOTRectData *data);
protected:
void updatePath(VPath& path, int frameNo) final;
LOTRectData *mData;
class LOTEllipseItem: public LOTPathDataItem
{
public:
- LOTEllipseItem(LOTEllipseData *data);
+ explicit LOTEllipseItem(LOTEllipseData *data);
private:
void updatePath(VPath& path, int frameNo) final;
LOTEllipseData *mData;
class LOTShapeItem: public LOTPathDataItem
{
public:
- LOTShapeItem(LOTShapeData *data);
+ explicit LOTShapeItem(LOTShapeData *data);
private:
void updatePath(VPath& path, int frameNo) final;
LOTShapeData *mData;
class LOTPolystarItem: public LOTPathDataItem
{
public:
- LOTPolystarItem(LOTPolystarData *data);
+ explicit LOTPolystarItem(LOTPolystarData *data);
private:
void updatePath(VPath& path, int frameNo) final;
LOTPolystarData *mData;
class LOTFillItem : public LOTPaintDataItem
{
public:
- LOTFillItem(LOTFillData *data);
+ explicit LOTFillItem(LOTFillData *data);
protected:
void updateContent(int frameNo) final;
void updateRenderNode() final;
class LOTGFillItem : public LOTPaintDataItem
{
public:
- LOTGFillItem(LOTGFillData *data);
+ explicit LOTGFillItem(LOTGFillData *data);
protected:
void updateContent(int frameNo) final;
void updateRenderNode() final;
class LOTStrokeItem : public LOTPaintDataItem
{
public:
- LOTStrokeItem(LOTStrokeData *data);
+ explicit LOTStrokeItem(LOTStrokeData *data);
protected:
void updateContent(int frameNo) final;
void updateRenderNode() final;
class LOTGStrokeItem : public LOTPaintDataItem
{
public:
- LOTGStrokeItem(LOTGStrokeData *data);
+ explicit LOTGStrokeItem(LOTGStrokeData *data);
protected:
void updateContent(int frameNo) final;
void updateRenderNode() final;
class LOTRepeaterItem : public LOTContentGroupItem
{
public:
- LOTRepeaterItem(LOTRepeaterData *data);
+ explicit LOTRepeaterItem(LOTRepeaterData *data);
void update(int frameNo, const VMatrix &parentMatrix, float parentAlpha, const DirtyFlag &flag) final;
void renderList(std::vector<VDrawable *> &list) final;
private:
- LOTRepeaterData *mData;
+ LOTRepeaterData *mRepeaterData;
bool mHidden{false};
int mCopies{0};
};
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
-#include "vdasher.h"
#include "vbezier.h"
+
+#include <cmath>
+
+#include "vdasher.h"
#include "vline.h"
V_BEGIN_NAMESPACE
-VDasher::VDasher(const float *dashArray, int size)
+VDasher::VDasher(const float *dashArray, size_t size)
{
mDashArray = reinterpret_cast<const VDasher::Dash *>(dashArray);
mArraySize = size / 2;
if (!vCompare(mDashOffset, 0.0f)) {
float totalLength = 0.0;
- for (int i = 0; i < mArraySize; i++) {
+ for (size_t i = 0; i < mArraySize; i++) {
totalLength = mDashArray[i].length + mDashArray[i].gap;
}
- float normalizeLen = fmod(mDashOffset, totalLength);
- if (normalizeLen < 0.0) {
+ float normalizeLen = std::fmod(mDashOffset, totalLength);
+ if (normalizeLen < 0.0f) {
normalizeLen = totalLength + normalizeLen;
}
// now the length is less than total length and +ve
// findout the current dash index , dashlength and gap.
- for (int i = 0; i < mArraySize; i++) {
+ for (size_t i = 0; i < mArraySize; i++) {
if (normalizeLen < mDashArray[i].length) {
mIndex = i;
mCurrentLength = mDashArray[i].length - normalizeLen;
mCurPt = line.p1();
}
// handle remainder
- if (length > 1.0) {
+ if (length > 1.0f) {
mCurrentLength -= length;
addLine(line.p2());
}
}
- if (mCurrentLength < 1.0) updateActiveSegment();
+ if (mCurrentLength < 1.0f) updateActiveSegment();
mCurPt = p;
}
void VDasher::cubicTo(const VPointF &cp1, const VPointF &cp2, const VPointF &e)
{
VBezier left, right;
- float bezLen = 0.0;
VBezier b = VBezier::fromPoints(mCurPt, cp1, cp2, e);
- bezLen = b.length();
+ float bezLen = b.length();
if (bezLen <= mCurrentLength) {
mCurrentLength -= bezLen;
mCurPt = b.pt1();
}
// handle remainder
- if (bezLen > 1.0) {
+ if (bezLen > 1.0f) {
mCurrentLength -= bezLen;
addCubic(b.pt2(), b.pt3(), b.pt4());
}
}
- if (mCurrentLength < 1.0) updateActiveSegment();
+ if (mCurrentLength < 1.0f) updateActiveSegment();
mCurPt = e;
}
// no need to do anything here.
break;
}
- default:
- break;
}
}
return std::move(mResult);
class VDasher {
public:
- VDasher(const float *dashArray, int size);
+ VDasher(const float *dashArray, size_t size);
VPath dashed(const VPath &path);
private:
float gap;
};
const VDasher::Dash *mDashArray;
- int mArraySize{0};
+ size_t mArraySize{0};
VPointF mCurPt;
- int mIndex{0}; /* index to the dash Array */
+ size_t mIndex{0}; /* index to the dash Array */
float mCurrentLength;
bool mDiscard;
float mDashOffset{0};
}
static inline Operator getOperator(const VSpanData * data,
- const VRle::Span *, int)
+ const VRle::Span *, size_t)
{
Operator op;
bool solidSource = false;
return op;
}
-static void blendColorARGB(int count, const VRle::Span *spans, void *userData)
+static void blendColorARGB(size_t count, const VRle::Span *spans, void *userData)
{
VSpanData *data = (VSpanData *)(userData);
Operator op = getOperator(data, spans, count);
}
#define BLEND_GRADIENT_BUFFER_SIZE 2048
-static void blendGradientARGB(int count, const VRle::Span *spans,
+static void blendGradientARGB(size_t count, const VRle::Span *spans,
void *userData)
{
VSpanData *data = (VSpanData *)(userData);
static const int buffer_size = 1024;
static const int fixed_scale = 1 << 16;
-static void blend_transformed_argb(int count, const VRle::Span *spans, void *userData)
+static void blend_transformed_argb(size_t count, const VRle::Span *spans, void *userData)
{
VSpanData *data = reinterpret_cast<VSpanData *>(userData);
if (data->mBitmap.format != VBitmap::Format::ARGB32_Premultiplied
}
}
-static void blend_untransformed_argb(int count, const VRle::Span *spans, void *userData)
+static void blend_untransformed_argb(size_t count, const VRle::Span *spans, void *userData)
{
VSpanData *data = reinterpret_cast<VSpanData *>(userData);
if (data->mBitmap.format != VBitmap::Format::ARGB32_Premultiplied
typedef void (*SourceFetchProc)(uint32_t *buffer, const Operator *o,
const VSpanData *data, int y, int x,
int length);
-typedef void (*ProcessRleSpan)(int count, const VRle::Span *spans,
+typedef void (*ProcessRleSpan)(size_t count, const VRle::Span *spans,
void *userData);
extern void memfill32(uint32_t *dest, uint32_t value, int count);
Shear = 0x08,
Project = 0x10
};
-
+ VMatrix() = default;
bool isAffine() const;
bool isIdentity() const;
bool isInvertible() const;
mLengthDirty = false;
mLength = 0.0;
- int i = 0;
+ size_t i = 0;
for (auto e : m_elements) {
switch (e) {
case VPath::Element::MoveTo:
mLengthDirty = false;
}
-int VPath::VPathData::segments() const
+size_t VPath::VPathData::segments() const
{
return m_segments;
}
-void VPath::VPathData::reserve(int pts, int elms)
+void VPath::VPathData::reserve(size_t pts, size_t elms)
{
if (m_points.capacity() < m_points.size() + pts)
m_points.reserve(m_points.size() + pts);
m_elements.reserve(m_elements.size() + elms);
}
-static VPointF curvesForArc(const VRectF &, float, float, VPointF *, int *);
-static constexpr float PATH_KAPPA = 0.5522847498;
+static VPointF curvesForArc(const VRectF &, float, float, VPointF *, size_t *);
+static constexpr float PATH_KAPPA = 0.5522847498f;
+static constexpr float K_PI = M_PIf32;
void VPath::VPathData::arcTo(const VRectF &rect, float startAngle,
float sweepLength, bool forceMoveTo)
{
- int point_count = 0;
+ size_t point_count = 0;
VPointF pts[15];
VPointF curve_start =
curvesForArc(rect, startAngle, sweepLength, pts, &point_count);
} else {
lineTo(curve_start.x(), curve_start.y());
}
- for (int i = 0; i < point_count; i += 3) {
+ for (size_t i = 0; i < point_count; i += 3) {
cubicTo(pts[i].x(), pts[i].y(), pts[i + 1].x(), pts[i + 1].y(),
pts[i + 2].x(), pts[i + 2].y());
}
void VPath::VPathData::addRoundRect(const VRectF &rect, float roundness,
VPath::Direction dir)
{
- if (2 * roundness > rect.width()) roundness = rect.width()/2.0;
- if (2 * roundness > rect.height()) roundness = rect.height()/2.0;
+ if (2 * roundness > rect.width()) roundness = rect.width()/2.0f;
+ if (2 * roundness > rect.height()) roundness = rect.height()/2.0f;
addRoundRect(rect, roundness, roundness, dir);
}
for (int i = 0; i < 2; ++i) {
if (!points[i]) continue;
- float theta = angles[i] - 360 * floor(angles[i] / 360);
+ float theta = angles[i] - 360 * floorf(angles[i] / 360);
float t = theta / 90;
// truncate
int quadrant = int(t);
if (vCompare(angle, 0.f)) return 0;
if (vCompare(angle, 90.0f)) return 1;
- radians = (angle / 180) * M_PI;
+ radians = (angle / 180) * K_PI;
- cos_angle = cos(radians);
- sin_angle = sin(radians);
+ cos_angle = cosf(radians);
+ sin_angle = sinf(radians);
// initial guess
tc = angle / 90;
// use the average of the t that best approximates cos_angle
// and the t that best approximates sin_angle
- t = 0.5 * (tc + ts);
+ t = 0.5f * (tc + ts);
return t;
}
// The return value is the starting point of the arc
static VPointF curvesForArc(const VRectF &rect, float startAngle,
float sweepLength, VPointF *curves,
- int *point_count)
+ size_t *point_count)
{
if (rect.empty()) {
return {};
sweepLength = -360;
// Special case fast paths
- if (startAngle == 0.0) {
- if (sweepLength == 360.0) {
+ if (startAngle == 0.0f) {
+ if (vCompare(sweepLength, 360)) {
for (int i = 11; i >= 0; --i) curves[(*point_count)++] = points[i];
return points[12];
- } else if (sweepLength == -360.0) {
+ } else if (vCompare(sweepLength, -360)) {
for (int i = 1; i <= 12; ++i) curves[(*point_count)++] = points[i];
return points[0];
}
}
- int startSegment = int(floor(startAngle / 90));
- int endSegment = int(floor((startAngle + sweepLength) / 90));
+ int startSegment = int(floorf(startAngle / 90.0f));
+ int endSegment = int(floorf((startAngle + sweepLength) / 90.0f));
float startT = (startAngle - startSegment * 90) / 90;
float endT = (startAngle + sweepLength - endSegment * 90) / 90;
float outerRoundness, float startAngle,
float cx, float cy, VPath::Direction dir)
{
- const static float POLYSTAR_MAGIC_NUMBER = 0.47829 / 0.28;
- float currentAngle = (startAngle - 90.0) * M_PI / 180.0;
+ const static float POLYSTAR_MAGIC_NUMBER = 0.47829f / 0.28f;
+ float currentAngle = (startAngle - 90.0f) * K_PI / 180.0f;
float x;
float y;
float partialPointRadius = 0;
- float anglePerPoint = (float)(2.0 * M_PI / points);
- float halfAnglePerPoint = anglePerPoint / 2.0;
- float partialPointAmount = points - (int)points;
+ float anglePerPoint = (2.0f * K_PI / points);
+ float halfAnglePerPoint = anglePerPoint / 2.0f;
+ float partialPointAmount = points - floorf(points);
bool longSegment = false;
- int numPoints = (int)ceil(points) * 2.0;
+ size_t numPoints = size_t(ceilf(points) * 2);
float angleDir = ((dir == VPath::Direction::CW) ? 1.0 : -1.0);
bool hasRoundness = false;
- innerRoundness /= 100.0;
- outerRoundness /= 100.0;
+ innerRoundness /= 100.0f;
+ outerRoundness /= 100.0f;
- if (partialPointAmount != 0) {
+ if (!vCompare(partialPointAmount, 0)) {
currentAngle +=
- halfAnglePerPoint * (1.0 - partialPointAmount) * angleDir;
+ halfAnglePerPoint * (1.0f - partialPointAmount) * angleDir;
}
- if (partialPointAmount != 0) {
+ if (!vCompare(partialPointAmount, 0)) {
partialPointRadius =
innerRadius + partialPointAmount * (outerRadius - innerRadius);
- x = (float)(partialPointRadius * cos(currentAngle));
- y = (float)(partialPointRadius * sin(currentAngle));
- currentAngle += anglePerPoint * partialPointAmount / 2.0 * angleDir;
+ x = partialPointRadius * cosf(currentAngle);
+ y = partialPointRadius * sinf(currentAngle);
+ currentAngle += anglePerPoint * partialPointAmount / 2.0f * angleDir;
} else {
- x = (float)(outerRadius * cos(currentAngle));
- y = (float)(outerRadius * sin(currentAngle));
+ x = outerRadius * cosf(currentAngle);
+ y = outerRadius * sinf(currentAngle);
currentAngle += halfAnglePerPoint * angleDir;
}
moveTo(x + cx, y + cy);
- for (int i = 0; i < numPoints; i++) {
+ for (size_t i = 0; i < numPoints; i++) {
float radius = longSegment ? outerRadius : innerRadius;
float dTheta = halfAnglePerPoint;
- if (partialPointRadius != 0 && i == numPoints - 2) {
- dTheta = anglePerPoint * partialPointAmount / 2.0;
+ if (!vIsZero(partialPointRadius) && i == numPoints - 2) {
+ dTheta = anglePerPoint * partialPointAmount / 2.0f;
}
- if (partialPointRadius != 0 && i == numPoints - 1) {
+ if (!vIsZero(partialPointRadius) && i == numPoints - 1) {
radius = partialPointRadius;
}
float previousX = x;
float previousY = y;
- x = (float)(radius * cos(currentAngle));
- y = (float)(radius * sin(currentAngle));
+ x = radius * cosf(currentAngle);
+ y = radius * sinf(currentAngle);
if (hasRoundness) {
float cp1Theta =
- (float)(atan2(previousY, previousX) - M_PI / 2.0 * angleDir);
- float cp1Dx = (float)cos(cp1Theta);
- float cp1Dy = (float)sin(cp1Theta);
- float cp2Theta = (float)(atan2(y, x) - M_PI / 2.0 * angleDir);
- float cp2Dx = (float)cos(cp2Theta);
- float cp2Dy = (float)sin(cp2Theta);
+ (atan2f(previousY, previousX) - K_PI / 2.0f * angleDir);
+ float cp1Dx = cosf(cp1Theta);
+ float cp1Dy = sinf(cp1Theta);
+ float cp2Theta = (atan2f(y, x) - K_PI / 2.0f * angleDir);
+ float cp2Dx = cosf(cp2Theta);
+ float cp2Dy = sinf(cp2Theta);
float cp1Roundness = longSegment ? innerRoundness : outerRoundness;
float cp2Roundness = longSegment ? outerRoundness : innerRoundness;
float cp2y = cp2Radius * cp2Roundness * POLYSTAR_MAGIC_NUMBER *
cp2Dy / points;
- if ((partialPointAmount != 0) &&
+ if (!vIsZero(partialPointAmount) &&
((i == 0) || (i == numPoints - 1))) {
cp1x *= partialPointAmount;
cp1y *= partialPointAmount;
{
// TODO: Need to support floating point number for number of points
const static float POLYGON_MAGIC_NUMBER = 0.25;
- float currentAngle = (startAngle - 90.0) * M_PI / 180.0;
+ float currentAngle = (startAngle - 90.0f) * K_PI / 180.0f;
float x;
float y;
- float anglePerPoint = (float)(2.0 * M_PI / floor(points));
- int numPoints = (int)floor(points);
+ float anglePerPoint = 2.0f * K_PI / floorf(points);
+ size_t numPoints = size_t(floorf(points));
float angleDir = ((dir == VPath::Direction::CW) ? 1.0 : -1.0);
bool hasRoundness = false;
- roundness /= 100.0;
+ roundness /= 100.0f;
- currentAngle = (currentAngle - 90.0) * M_PI / 180.0;
- x = (float)(radius * cos(currentAngle));
- y = (float)(radius * sin(currentAngle));
+ currentAngle = (currentAngle - 90.0f) * K_PI / 180.0f;
+ x = radius * cosf(currentAngle);
+ y = radius * sinf(currentAngle);
currentAngle += anglePerPoint * angleDir;
if (vIsZero(roundness)) {
moveTo(x + cx, y + cy);
- for (int i = 0; i < numPoints; i++) {
+ for (size_t i = 0; i < numPoints; i++) {
float previousX = x;
float previousY = y;
- x = (float)(radius * cos(currentAngle));
- y = (float)(radius * sin(currentAngle));
+ x = (radius * cosf(currentAngle));
+ y = (radius * sinf(currentAngle));
if (hasRoundness) {
float cp1Theta =
- (float)(atan2(previousY, previousX) - M_PI / 2.0 * angleDir);
- float cp1Dx = (float)cos(cp1Theta);
- float cp1Dy = (float)sin(cp1Theta);
- float cp2Theta = (float)(atan2(y, x) - M_PI / 2.0 * angleDir);
- float cp2Dx = (float)cos(cp2Theta);
- float cp2Dy = (float)sin(cp2Theta);
+ (atan2f(previousY, previousX) - K_PI / 2.0f * angleDir);
+ float cp1Dx = cosf(cp1Theta);
+ float cp1Dy = sinf(cp1Theta);
+ float cp2Theta = atan2f(y, x) - K_PI / 2.0f * angleDir;
+ float cp2Dx = cosf(cp2Theta);
+ float cp2Dy = sinf(cp2Theta);
float cp1x = radius * roundness * POLYGON_MAGIC_NUMBER * cp1Dx;
float cp1y = radius * roundness * POLYGON_MAGIC_NUMBER * cp1Dy;
void VPath::VPathData::addPath(const VPathData &path)
{
- int segment = path.segments();
+ size_t segment = path.segments();
// make sure enough memory available
if (m_points.capacity() < m_points.size() + path.m_points.size())
bool forceMoveTo);
void close();
void reset();
- void reserve(int pts, int elms);
- int segments() const;
+ void reserve(size_t pts, size_t elms);
+ size_t segments() const;
void addCircle(float cx, float cy, float radius,
VPath::Direction dir = Direction::CW);
void addOval(const VRectF &rect, VPath::Direction dir = Direction::CW);
void cubicTo(float cx1, float cy1, float cx2, float cy2, float ex, float ey);
void close();
void reset();
- void reserve(int, int);
+ void reserve(size_t, size_t);
void checkNewSegment();
- int segments() const;
+ size_t segments() const;
void transform(const VMatrix &m);
float length() const;
void addRoundRect(const VRectF &, float, float, VPath::Direction);
const std::vector<VPointF> &points() const { return m_points; }
std::vector<VPointF> m_points;
std::vector<VPath::Element> m_elements;
- int m_segments;
+ unsigned int m_segments;
VPointF mStartPoint;
mutable float mLength{0};
mutable bool mLengthDirty{true};
d.write().reset();
}
-inline void VPath::reserve(int pts, int elms)
+inline void VPath::reserve(size_t pts, size_t elms)
{
d.write().reserve(pts, elms);
}
-inline int VPath::segments() const
+inline size_t VPath::segments() const
{
return d->segments();
}
void close();
void end();
void transform(const VMatrix &m);
+ SW_FT_Pos TO_FT_COORD(float x) { return SW_FT_Pos(x*64);} // to freetype 26.6 coordinate.
SW_FT_Outline ft;
bool closed{false};
SW_FT_Stroker_LineCap ftCap;
case VPath::Element::Close:
close();
break;
- default:
- break;
}
}
end();
{
// map strokeWidth to freetype. It uses as the radius of the pen not the
// diameter
- width = width / 2.0;
+ width = width / 2.0f;
// convert to freetype co-ordinate
// IMP: stroker takes radius in 26.6 co-ordinate
ftWidth = SW_FT_Fixed(width * (1 << 6));
}
}
-#define TO_FT_COORD(x) ((x)*64) // to freetype 26.6 coordinate.
-
void FTOutline::moveTo(const VPointF &pt)
{
ft.points[ft.n_points].x = TO_FT_COORD(pt.x());
static void rleGenerationCb(int count, const SW_FT_Span *spans, void *user)
{
- VRle * rle = (VRle *)user;
- VRle::Span *rleSpan = (VRle::Span *)spans;
+ VRle * rle = static_cast<VRle *>(user);
+ auto *rleSpan = reinterpret_cast<const VRle::Span *>(spans);
rle->addSpan(rleSpan, count);
}
static void bboxCb(int x, int y, int w, int h, void *user)
{
- VRle * rle = (VRle *)user;
+ VRle * rle = static_cast<VRle *>(user);
rle->setBoundingRect({x, y, w, h});
}
class SharedRle {
public:
+ SharedRle() = default;
VRle& unsafe(){ return _rle;}
void notify() {
{
public:
VRect() = default;
VRect(int x, int y, int w, int h):x1(x),y1(y),x2(x+w),y2(y+h){}
- VRect(const VRectF &r);
+ explicit VRect(const VRectF &r);
V_CONSTEXPR bool empty() const {return x1 >= x2 || y1 >= y2;}
V_CONSTEXPR int left() const {return x1;}
V_CONSTEXPR int top() const {return y1;}
public:
VRectF() = default;
VRectF(float x, float y, float w, float h):x1(x),y1(y),x2(x+w),y2(y+h){}
- VRectF(const VRect &r):x1(r.left()),y1(r.top()),
- x2(r.right()),y2(r.bottom()){}
+ explicit VRectF(const VRect &r):x1(r.left()),y1(r.top()),
+ x2(r.right()),y2(r.bottom()){}
V_CONSTEXPR bool empty() const {return x1 >= x2 || y1 >= y2;}
V_CONSTEXPR float left() const {return x1;}
};
struct VRleHelper {
- ushort alloc;
- ushort size;
+ size_t alloc;
+ size_t size;
VRle::Span *spans;
};
static void rleIntersectWithRle(VRleHelper *, int, int, VRleHelper *,
return (x + (x >> 8) + 0x80) >> 8;
}
-inline static void copyArrayToVector(const VRle::Span *span, int count,
+inline static void copyArrayToVector(const VRle::Span *span, size_t count,
std::vector<VRle::Span> &v)
{
// make sure enough memory available
std::copy(span, span + count, back_inserter(v));
}
-void VRle::VRleData::addSpan(const VRle::Span *span, int count)
+void VRle::VRleData::addSpan(const VRle::Span *span, size_t count)
{
copyArrayToVector(span, count, mSpans);
mBboxDirty = true;
int width = rect.width();
int height = rect.height();
- mSpans.reserve(height);
+ mSpans.reserve(size_t(height));
VRle::Span span;
for (int i = 0; i < height; i++) {
// 1. forward till both y intersect
while ((aPtr != aEnd) && (aPtr->y < bPtr->y)) aPtr++;
- int sizeA = aPtr - a.mSpans.data();
+ size_t sizeA = size_t(aPtr - a.mSpans.data());
if (sizeA) copyArrayToVector(a.mSpans.data(), sizeA, mSpans);
// 2. forward b till it intersect with a.
while ((bPtr != bEnd) && (bPtr->y < aPtr->y)) bPtr++;
- int sizeB = bPtr - b.mSpans.data();
+ size_t sizeB = size_t(bPtr - b.mSpans.data());
// 2. calculate the intersect region
VRleHelper tresult, aObj, bObj;
// 1. forward a till it intersects with b
while ((aPtr != aEnd) && (aPtr->y < bPtr->y)) aPtr++;
- int sizeA = aPtr - a.mSpans.data();
+ size_t sizeA = size_t(aPtr - a.mSpans.data());
if (sizeA) copyArrayToVector(a.mSpans.data(), sizeA, mSpans);
// 2. forward b till it intersects with a
while ((bPtr != bEnd) && (bPtr->y < aPtr->y)) bPtr++;
- int sizeB = bPtr - b.mSpans.data();
+ size_t sizeB = size_t(bPtr - b.mSpans.data());
if (sizeB) copyArrayToVector(b.mSpans.data(), sizeB, mSpans);
// 3. calculate the intersect region
case OpCode::Xor:
op = Operation::Xor;
break;
- default:
- break;
}
// run till all the spans are processed
while (aObj.size && bObj.size) {
mBboxDirty = false;
}
-static void rle_cb(int count, const VRle::Span *spans, void *userData)
+static void rle_cb(size_t count, const VRle::Span *spans, void *userData)
{
auto vector = static_cast<std::vector<VRle::Span> *>(userData);
copyArrayToVector(spans, count, *vector);
++spans;
continue;
}
- x = VMAX(sx1, cx1);
- len = VMIN(sx2, cx2) - x;
+ x = std::max(sx1, cx1);
+ len = std::min(sx2, cx2) - x;
if (len) {
- out->x = VMAX(sx1, cx1);
- out->len = (VMIN(sx2, cx2) - out->x);
+ out->x = std::max(sx1, cx1);
+ out->len = (std::min(sx2, cx2) - out->x);
out->y = spans->y;
out->coverage = divBy255(spans->coverage * clipSpans->coverage);
++out;
}
}
-int bufferToRle(uchar *buffer, int size, int offsetX, int y, VRle::Span *out)
+size_t bufferToRle(uchar *buffer, int size, int offsetX, int y, VRle::Span *out)
{
- int count = 0;
+ size_t count = 0;
uchar value = buffer[0];
int curIndex = 0;
{
std::array<VRle::Span, 256> temp;
VRle::Span * out = result->spans;
- int available = result->alloc;
+ size_t available = result->alloc;
VRle::Span * aPtr = a->spans;
VRle::Span * aEnd = a->spans + a->size;
VRle::Span * bPtr = b->spans;
else if (op == Operation::Xor)
blitXor(bStart, (bPtr - bStart), array.data(), -offset);
VRle::Span *tResult = temp.data();
- int size = bufferToRle(array.data(), std::max(aLength, bLength),
+ size_t size = bufferToRle(array.data(), std::max(aLength, bLength),
offset, y, tResult);
if (available >= size) {
while (size--) {
{
std::array<VRle::Span, 256> temp;
VRle::Span * out = result->spans;
- int available = result->alloc;
+ size_t available = result->alloc;
VRle::Span * aPtr = a->spans;
VRle::Span * aEnd = a->spans + a->size;
VRle::Span * bPtr = b->spans;
blit(aStart, (aPtr - aStart), array.data(), -offset);
blitDestinationOut(bStart, (bPtr - bStart), array.data(), -offset);
VRle::Span *tResult = temp.data();
- int size = bufferToRle(array.data(), std::max(aLength, bLength),
+ size_t size = bufferToRle(array.data(), std::max(aLength, bLength),
offset, y, tResult);
if (available >= size) {
while (size--) {
}
// update the span list that yet to be processed
a->spans = aPtr;
- a->size = aEnd - aPtr;
+ a->size = size_t(aEnd - aPtr);
// update the clip list that yet to be processed
b->spans = bPtr;
- b->size = bEnd - bPtr;
+ b->size = size_t(bEnd - bPtr);
// update the result
result->size = result->alloc - available;
ushort len;
uchar coverage;
};
- typedef void (*VRleSpanCb)(int count, const VRle::Span *spans,
+ typedef void (*VRleSpanCb)(size_t count, const VRle::Span *spans,
void *userData);
bool empty() const;
VRect boundingRect() const;
void setBoundingRect(const VRect &bbox);
- void addSpan(const VRle::Span *span, int count);
+ void addSpan(const VRle::Span *span, size_t count);
void reset();
void translate(const VPoint &p);
Xor
};
bool empty() const { return mSpans.empty(); }
- void addSpan(const VRle::Span *span, int count);
+ void addSpan(const VRle::Span *span, size_t count);
void updateBbox() const;
VRect bbox() const;
void setBbox(const VRect &bbox) const;
return d->empty();
}
-inline void VRle::addSpan(const VRle::Span *span, int count)
+inline void VRle::addSpan(const VRle::Span *span, size_t count)
{
d.write().addSpan(span, count);
}