+bool layer::vector_mask_info::populate(int length, bigendian_file_input_stream& stream, int doc_width, int doc_height)
+{
+ typedef std::pair<int, int> path_point;
+ bool bFail = false;
+
+ stream.read_long(); // version
+ this->flags_ = static_cast<std::uint8_t>(stream.read_long()); // flags
+ int path_records = (length - 8) / 26;
+
+ auto position = stream.current_position();
+
+ std::vector<path_point> knots;
+
+ const int SELECTOR_SIZE = 2;
+ const int PATH_POINT_SIZE = 4 + 4;
+ const int PATH_POINT_RECORD_SIZE = SELECTOR_SIZE + (3 * PATH_POINT_SIZE);
+
+ for (int i = 1; i <= path_records; ++i)
+ {
+ auto selector = stream.read_short();
+ if (selector == 2) //we only concern ourselves with closed paths
+ {
+ auto p_y = stream.read_long();
+ auto p_x = stream.read_long();
+ path_point cp_prev(p_x, p_y);
+
+ auto a_y = stream.read_long();
+ auto a_x = stream.read_long();
+ path_point anchor(a_x, a_y);
+
+ auto n_y = stream.read_long();
+ auto n_x = stream.read_long();
+ path_point cp_next(n_x, n_y);
+
+ if (anchor == cp_prev && anchor == cp_next)
+ knots.push_back(anchor);
+ else
+ { //we can't handle smooth curves yet
+ bFail = true;
+ }
+ }
+
+ auto offset = PATH_POINT_RECORD_SIZE * i;
+ stream.set_position(position + offset);
+ }
+
+ if ((knots.size() != 4) || (!(knots[0].first == knots[3].first && knots[1].first == knots[2].first && knots[0].second == knots[1].second && knots[2].second == knots[3].second)))
+ bFail = true;
+
+ if (bFail) {
+ rect_.clear();
+ flags_ = static_cast<std::uint8_t>(flags::unsupported);
+ }
+ else
+ {
+ //the path_points are given in fixed-point 8.24 as a ratio with regards to the width/height of the document. we need to divide by 16777215.0f to get the real ratio.
+ float x_ratio = doc_width / 16777215.0f;
+ float y_ratio = doc_height / 16777215.0f;
+ rect_.location.x = static_cast<int>(knots[0].first * x_ratio + 0.5f); //add .5 to get propper rounding when converting to integer
+ rect_.location.y = static_cast<int>(knots[0].second * y_ratio + 0.5f); //add .5 to get propper rounding when converting to integer
+ rect_.size.width = static_cast<int>(knots[1].first * x_ratio + 0.5f) - rect_.location.x; //add .5 to get propper rounding when converting to integer
+ rect_.size.height = static_cast<int>(knots[2].second * y_ratio + 0.5f) - rect_.location.y; //add .5 to get propper rounding when converting to integer
+ }
+
+ return !bFail;
+}
+