mirror of
https://github.com/bkaradzic/bimg.git
synced 2026-10-06 08:55:39 +00:00
SVG: Round document size to the nearest pixel. (#158)
This commit is contained in:
committed by
GitHub
parent
8869e43603
commit
b96a703d89
@@ -35,9 +35,10 @@ namespace bimg
|
||||
///
|
||||
/// @remarks
|
||||
/// Aspect ratio is always preserved. When both `_width` and `_height` are given the image is
|
||||
/// scaled to fit inside of them. When both are 0 the image is rasterized at the size stated
|
||||
/// in the document, scaled down if needed to fit inside of 4096x4096, which is also what
|
||||
/// `bimg::imageParse` does.
|
||||
/// scaled to fit inside of them. When both are 0 documents that fit inside of 4096x4096 are
|
||||
/// rasterized at native scale, with pixel dimensions rounded to the nearest integer (half
|
||||
/// up). Dimensions rounding to 0 are rejected. Larger documents are scaled down to fit
|
||||
/// inside of 4096x4096. `bimg::imageParse` and `bimg::imageParseInfo` use the same size policy.
|
||||
///
|
||||
ImageContainer* imageParseSvg(
|
||||
bx::AllocatorI* _allocator
|
||||
|
||||
@@ -1599,14 +1599,19 @@ namespace bimg
|
||||
if (0 == _width
|
||||
&& 0 == _height)
|
||||
{
|
||||
_width = uint32_t(bx::ceil(bx::min(width, float(kSvgMaxSize) ) ) );
|
||||
_height = uint32_t(bx::ceil(bx::min(height, float(kSvgMaxSize) ) ) );
|
||||
|
||||
if (width <= float(kSvgMaxSize)
|
||||
&& height <= float(kSvgMaxSize) )
|
||||
{
|
||||
_outWidth = _width;
|
||||
_outHeight = _height;
|
||||
_outWidth = uint32_t(bx::floor(width + 0.5f) );
|
||||
_outHeight = uint32_t(bx::floor(height + 0.5f) );
|
||||
if (0 == _outWidth
|
||||
|| 0 == _outHeight)
|
||||
{
|
||||
nsvgDelete(image);
|
||||
BX_ERROR_SET(_err, BIMG_ERROR, "SVG: Unsupported dimensions.");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
_outScale = 1.0f;
|
||||
|
||||
return image;
|
||||
|
||||
Reference in New Issue
Block a user