common: new api for a grad transformation
authorMira Grudzinska <m.grudzinska@samsung.com>
Mon, 11 Oct 2021 13:20:03 +0000 (15:20 +0200)
committerJunsuChoi <jsuya.choi@samsung.com>
Wed, 20 Oct 2021 04:50:36 +0000 (13:50 +0900)
The new apii allows to transform the gradient fill.

inc/thorvg.h
src/lib/tvgFill.cpp
src/lib/tvgFill.h

index 502d16dcbbf34dc3a033f3e461db536212c2f88a..69bd051bb0ac413097384a13e176b8929f2bbd42 100644 (file)
@@ -392,10 +392,23 @@ public:
      */
     Result spread(FillSpread s) noexcept;
 
+    /**
+     * @brief Sets the matrix of the affine transformation for the gradient fill.
+     *
+     * The augmented matrix of the transformation is expected to be given.
+     *
+     * @param[in] m The 3x3 augmented matrix.
+     *
+     * @return Result::Success when succeed, Result::FailedAllocation otherwise.
+     *
+     * @BETA_API
+     */
+    Result transform(const Matrix& m) noexcept;
+
     /**
      * @brief Gets the parameters of the colors of the gradient, their position and number.
      *
-     * @param[in] colorStops A pointer to the memory location, where the array of the gradient's ColorStop is stored.
+     * @param[out] colorStops A pointer to the memory location, where the array of the gradient's ColorStop is stored.
      *
      * @return The number of colors used in the gradient. This value corresponds to the length of the @p colorStops array.
      */
@@ -408,6 +421,17 @@ public:
      */
     FillSpread spread() const noexcept;
 
+    /**
+     * @brief Gets the matrix of the affine transformation of the gradient fill.
+     *
+     * In case no transformation was applied, the identity matrix is returned.
+     *
+     * @retval The augmented transformation matrix.
+     *
+     * @BETA_API
+     */
+    Matrix transform() const noexcept;
+
     /**
      * @brief Creates a copy of the Fill object.
      *
@@ -1375,7 +1399,7 @@ public:
  * It's useful when you need to save the composed scene or image from a paint object and recreate it later.
  *
  * The file format is decided by the extension name(i.e. "*.tvg") while the supported formats depend on the TVG packaging environment.
- * If it doesn't support the file format, the save() method returns the @c NonSuppport result.
+ * If it doesn't support the file format, the save() method returns the @c Result::NonSuppport result.
  *
  * Once you export a paint to the file successfully, you can recreate it using the Picture class.
  *
index 757f78b9517c3c68bdb7d7c1a843e2432ff6a1df..b610a775e61cd984f204e3b3512d73cfc0098514 100644 (file)
@@ -87,6 +87,22 @@ FillSpread Fill::spread() const noexcept
 }
 
 
+Result Fill::transform(const Matrix& m) noexcept
+{
+    if (!pImpl->transform) pImpl->transform = new Matrix();
+    if (!pImpl->transform) return Result::FailedAllocation;
+    *pImpl->transform = m;
+    return Result::Success;
+}
+
+
+Matrix Fill::transform() const noexcept
+{
+    if (pImpl->transform) return *pImpl->transform;
+    return {1, 0, 0, 0, 1, 0, 0, 0, 1};
+}
+
+
 Fill* Fill::duplicate() const noexcept
 {
     return pImpl->duplicate();
index f9eaddffaf77e7605f5da9d1ec70aef9b5d42426..16a0097fcf40fdbc2ca5d97fc76af60423de24e6 100644 (file)
@@ -50,6 +50,7 @@ struct FillDup : DuplicateMethod<Fill>
 struct Fill::Impl
 {
     ColorStop* colorStops = nullptr;
+    Matrix* transform = nullptr;
     uint32_t cnt = 0;
     FillSpread spread;
     DuplicateMethod<Fill>* dup = nullptr;
@@ -58,6 +59,7 @@ struct Fill::Impl
     {
         if (dup) delete(dup);
         if (colorStops) free(colorStops);
+        if (transform) delete(transform);
     }
 
     void method(DuplicateMethod<Fill>* dup)
@@ -74,7 +76,10 @@ struct Fill::Impl
         ret->pImpl->spread = spread;
         ret->pImpl->colorStops = static_cast<ColorStop*>(malloc(sizeof(ColorStop) * cnt));
         memcpy(ret->pImpl->colorStops, colorStops, sizeof(ColorStop) * cnt);
-
+        if (transform) {
+            ret->pImpl->transform = new Matrix;
+            if (ret->pImpl->transform) *ret->pImpl->transform = *transform;
+        }
         return ret;
     }
 };