Icon-O-Matic: check number of items when exporting
Silently saving only part of the data is not nice and confusing. The error message just says "Out of range" now however, which is not really great either. We could improve the error reporting, and, as mentionned in the ticket, also warn in the UI when the limit is reached (a marker near the shape/path/fill lists maybe?) so the user knows they need to simplify their picture. Part of #13978 Change-Id: I978ff3d377b3652c7f1c5fac4f429ade0398d5f7 Reviewed-on: https://review.haiku-os.org/c/haiku/+/2852 Reviewed-by: waddlesplash <[email protected]>
This commit is contained in:
committed by
waddlesplash
parent
c12a0f8ebb
commit
92ed372680
@@ -212,6 +212,8 @@ status_t
|
||||
FlatIconExporter::_WriteStyles(LittleEndianBuffer& buffer,
|
||||
StyleContainer* styles)
|
||||
{
|
||||
if (styles->CountStyles() > 255)
|
||||
return B_RESULT_NOT_REPRESENTABLE;
|
||||
uint8 styleCount = min_c(255, styles->CountStyles());
|
||||
if (!buffer.Write(styleCount))
|
||||
return B_NO_MEMORY;
|
||||
@@ -369,6 +371,8 @@ write_path_with_commands(LittleEndianBuffer& buffer, VectorPath* path,
|
||||
status_t
|
||||
FlatIconExporter::_WritePaths(LittleEndianBuffer& buffer, PathContainer* paths)
|
||||
{
|
||||
if (paths->CountPaths() > 255)
|
||||
return B_RESULT_NOT_REPRESENTABLE;
|
||||
uint8 pathCount = min_c(255, paths->CountPaths());
|
||||
if (!buffer.Write(pathCount))
|
||||
return B_NO_MEMORY;
|
||||
@@ -379,6 +383,8 @@ FlatIconExporter::_WritePaths(LittleEndianBuffer& buffer, PathContainer* paths)
|
||||
if (path->IsClosed())
|
||||
pathFlags |= PATH_FLAG_CLOSED;
|
||||
|
||||
if (path->CountPoints() > 255)
|
||||
return B_RESULT_NOT_REPRESENTABLE;
|
||||
uint8 pointCount = min_c(255, path->CountPoints());
|
||||
|
||||
// see if writing segments with commands is more efficient
|
||||
@@ -490,6 +496,8 @@ _WritePathSourceShape(LittleEndianBuffer& buffer, Shape* shape,
|
||||
if (styleIndex < 0 || styleIndex > 255)
|
||||
return false;
|
||||
|
||||
if (shape->Paths()->CountPaths() > 255)
|
||||
return B_RESULT_NOT_REPRESENTABLE;
|
||||
uint8 pathCount = min_c(255, shape->Paths()->CountPaths());
|
||||
|
||||
// write shape type and style index
|
||||
@@ -509,6 +517,8 @@ _WritePathSourceShape(LittleEndianBuffer& buffer, Shape* shape,
|
||||
return false;
|
||||
}
|
||||
|
||||
if (shape->CountTransformers() > 255)
|
||||
return B_RESULT_NOT_REPRESENTABLE;
|
||||
uint8 transformerCount = min_c(255, shape->CountTransformers());
|
||||
|
||||
// shape flags
|
||||
@@ -572,6 +582,8 @@ FlatIconExporter::_WriteShapes(LittleEndianBuffer& buffer,
|
||||
PathContainer* paths,
|
||||
ShapeContainer* shapes)
|
||||
{
|
||||
if (shapes->CountShapes() > 255)
|
||||
return B_RESULT_NOT_REPRESENTABLE;
|
||||
uint8 shapeCount = min_c(255, shapes->CountShapes());
|
||||
if (!buffer.Write(shapeCount))
|
||||
return B_NO_MEMORY;
|
||||
|
||||
Reference in New Issue
Block a user