mirror of
https://github.com/morgan9e/FreeRDP
synced 2026-04-15 00:44:19 +09:00
[rdtk] fix integer casts
This commit is contained in:
@@ -17,6 +17,7 @@
|
||||
*/
|
||||
|
||||
#include <winpr/assert.h>
|
||||
#include <winpr/cast.h>
|
||||
|
||||
#include <rdtk/config.h>
|
||||
|
||||
@@ -27,12 +28,8 @@
|
||||
int rdtk_button_draw(rdtkSurface* surface, uint16_t nXDst, uint16_t nYDst, uint16_t nWidth,
|
||||
uint16_t nHeight, rdtkButton* button, const char* text)
|
||||
{
|
||||
uint16_t offsetX = 0;
|
||||
uint16_t offsetY = 0;
|
||||
uint16_t textWidth = 0;
|
||||
uint16_t textHeight = 0;
|
||||
uint16_t fillWidth = 0;
|
||||
uint16_t fillHeight = 0;
|
||||
|
||||
WINPR_ASSERT(surface);
|
||||
WINPR_ASSERT(button);
|
||||
@@ -48,21 +45,35 @@ int rdtk_button_draw(rdtkSurface* surface, uint16_t nXDst, uint16_t nYDst, uint1
|
||||
|
||||
if ((textWidth > 0) && (textHeight > 0))
|
||||
{
|
||||
fillWidth = nWidth - (ninePatch->width - ninePatch->fillWidth);
|
||||
fillHeight = nHeight - (ninePatch->height - ninePatch->fillHeight);
|
||||
const int wd = (ninePatch->width - ninePatch->fillWidth);
|
||||
const int hd = (ninePatch->height - ninePatch->fillHeight);
|
||||
|
||||
offsetX = ninePatch->fillLeft;
|
||||
offsetY = ninePatch->fillTop;
|
||||
const uint16_t fillWidth = nWidth - WINPR_ASSERTING_INT_CAST(uint16_t, wd);
|
||||
const uint16_t fillHeight = nHeight - WINPR_ASSERTING_INT_CAST(uint16_t, hd);
|
||||
uint16_t offsetX = WINPR_ASSERTING_INT_CAST(UINT16, ninePatch->fillLeft);
|
||||
uint16_t offsetY = WINPR_ASSERTING_INT_CAST(UINT16, ninePatch->fillTop);
|
||||
|
||||
if (textWidth < fillWidth)
|
||||
offsetX = ((fillWidth - textWidth) / 2) + ninePatch->fillLeft;
|
||||
{
|
||||
const int twd = ((fillWidth - textWidth) / 2) + ninePatch->fillLeft;
|
||||
offsetX = WINPR_ASSERTING_INT_CAST(uint16_t, twd);
|
||||
}
|
||||
else if (textWidth < ninePatch->width)
|
||||
offsetX = ((ninePatch->width - textWidth) / 2);
|
||||
{
|
||||
const int twd = ((ninePatch->width - textWidth) / 2);
|
||||
offsetX = WINPR_ASSERTING_INT_CAST(uint16_t, twd);
|
||||
}
|
||||
|
||||
if (textHeight < fillHeight)
|
||||
offsetY = ((fillHeight - textHeight) / 2) + ninePatch->fillTop;
|
||||
{
|
||||
const int twd = ((fillHeight - textHeight) / 2) + ninePatch->fillTop;
|
||||
offsetY = WINPR_ASSERTING_INT_CAST(uint16_t, twd);
|
||||
}
|
||||
else if (textHeight < ninePatch->height)
|
||||
offsetY = ((ninePatch->height - textHeight) / 2);
|
||||
{
|
||||
const int twd = ((ninePatch->height - textHeight) / 2);
|
||||
offsetY = WINPR_ASSERTING_INT_CAST(uint16_t, twd);
|
||||
}
|
||||
|
||||
rdtk_font_draw_text(surface, nXDst + offsetX, nYDst + offsetY, font, text);
|
||||
}
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
#include <winpr/wtypes.h>
|
||||
#include <winpr/crt.h>
|
||||
#include <winpr/assert.h>
|
||||
#include <winpr/cast.h>
|
||||
#include <winpr/path.h>
|
||||
#include <winpr/file.h>
|
||||
#include <winpr/print.h>
|
||||
@@ -40,8 +41,8 @@
|
||||
#define FILE_EXT "bmp"
|
||||
#endif
|
||||
|
||||
static int rdtk_font_draw_glyph(rdtkSurface* surface, int nXDst, int nYDst, rdtkFont* font,
|
||||
rdtkGlyph* glyph)
|
||||
static int rdtk_font_draw_glyph(rdtkSurface* surface, uint16_t nXDst, uint16_t nYDst,
|
||||
rdtkFont* font, rdtkGlyph* glyph)
|
||||
{
|
||||
WINPR_ASSERT(surface);
|
||||
WINPR_ASSERT(font);
|
||||
@@ -49,21 +50,21 @@ static int rdtk_font_draw_glyph(rdtkSurface* surface, int nXDst, int nYDst, rdtk
|
||||
|
||||
nXDst += glyph->offsetX;
|
||||
nYDst += glyph->offsetY;
|
||||
const int nXSrc = glyph->rectX;
|
||||
const int nYSrc = glyph->rectY;
|
||||
const int nWidth = glyph->rectWidth;
|
||||
const int nHeight = glyph->rectHeight;
|
||||
const size_t nXSrc = WINPR_ASSERTING_INT_CAST(size_t, glyph->rectX);
|
||||
const size_t nYSrc = WINPR_ASSERTING_INT_CAST(size_t, glyph->rectY);
|
||||
const size_t nWidth = WINPR_ASSERTING_INT_CAST(size_t, glyph->rectWidth);
|
||||
const size_t nHeight = WINPR_ASSERTING_INT_CAST(size_t, glyph->rectHeight);
|
||||
const uint32_t nSrcStep = font->image->scanline;
|
||||
const uint8_t* pSrcData = font->image->data;
|
||||
uint8_t* pDstData = surface->data;
|
||||
const uint32_t nDstStep = surface->scanline;
|
||||
|
||||
for (int y = 0; y < nHeight; y++)
|
||||
for (size_t y = 0; y < nHeight; y++)
|
||||
{
|
||||
const uint8_t* pSrcPixel = &pSrcData[((nYSrc + y) * nSrcStep) + (nXSrc * 4)];
|
||||
uint8_t* pDstPixel = &pDstData[((nYDst + y) * nDstStep) + (nXDst * 4)];
|
||||
const uint8_t* pSrcPixel = &pSrcData[((1ULL * nYSrc + y) * nSrcStep) + (4ULL * nXSrc)];
|
||||
uint8_t* pDstPixel = &pDstData[((1ULL * nYDst + y) * nDstStep) + (4ULL * nXDst)];
|
||||
|
||||
for (int x = 0; x < nWidth; x++)
|
||||
for (size_t x = 0; x < nWidth; x++)
|
||||
{
|
||||
uint8_t B = pSrcPixel[0];
|
||||
uint8_t G = pSrcPixel[1];
|
||||
@@ -133,7 +134,7 @@ int rdtk_font_text_draw_size(rdtkFont* font, uint16_t* width, uint16_t* height,
|
||||
const size_t length = strlen(text);
|
||||
for (size_t index = 0; index < length; index++)
|
||||
{
|
||||
const size_t glyphIndex = text[index] - 32;
|
||||
const size_t glyphIndex = WINPR_ASSERTING_INT_CAST(size_t, text[index] - 32);
|
||||
|
||||
if (glyphIndex < font->glyphCount)
|
||||
{
|
||||
@@ -216,7 +217,7 @@ static int rdtk_font_convert_descriptor_code_to_utf8(const char* str, uint8_t* u
|
||||
{
|
||||
if ((str[0] > 31) && (str[0] < 127))
|
||||
{
|
||||
utf8[0] = str[0];
|
||||
utf8[0] = WINPR_ASSERTING_INT_CAST(uint8_t, str[0] & 0xFF);
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -330,12 +331,12 @@ static int rdtk_font_parse_descriptor_buffer(rdtkFont* font, char* buffer, size_
|
||||
*q = '\0';
|
||||
errno = 0;
|
||||
{
|
||||
long val = strtol(p, NULL, 0);
|
||||
const unsigned long val = strtoul(p, NULL, 0);
|
||||
|
||||
if ((errno != 0) || (val < INT32_MIN) || (val > INT32_MAX))
|
||||
if ((errno != 0) || (val > UINT16_MAX))
|
||||
goto fail;
|
||||
|
||||
font->height = val;
|
||||
font->height = (uint16_t)val;
|
||||
}
|
||||
*q = '"';
|
||||
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
*/
|
||||
|
||||
#include <winpr/assert.h>
|
||||
#include <winpr/cast.h>
|
||||
|
||||
#include <rdtk/config.h>
|
||||
|
||||
@@ -27,24 +28,17 @@
|
||||
int rdtk_text_field_draw(rdtkSurface* surface, uint16_t nXDst, uint16_t nYDst, uint16_t nWidth,
|
||||
uint16_t nHeight, rdtkTextField* textField, const char* text)
|
||||
{
|
||||
uint16_t offsetX = 0;
|
||||
uint16_t offsetY = 0;
|
||||
uint16_t textWidth = 0;
|
||||
uint16_t textHeight = 0;
|
||||
uint16_t fillWidth = 0;
|
||||
uint16_t fillHeight = 0;
|
||||
rdtkFont* font = NULL;
|
||||
rdtkEngine* engine = NULL;
|
||||
rdtkNinePatch* ninePatch = NULL;
|
||||
|
||||
WINPR_ASSERT(surface);
|
||||
WINPR_ASSERT(textField);
|
||||
WINPR_ASSERT(text);
|
||||
|
||||
engine = surface->engine;
|
||||
font = engine->font;
|
||||
rdtkEngine* engine = surface->engine;
|
||||
rdtkFont* font = engine->font;
|
||||
textField = surface->engine->textField;
|
||||
ninePatch = textField->ninePatch;
|
||||
rdtkNinePatch* ninePatch = textField->ninePatch;
|
||||
|
||||
rdtk_font_text_draw_size(font, &textWidth, &textHeight, text);
|
||||
|
||||
@@ -52,21 +46,35 @@ int rdtk_text_field_draw(rdtkSurface* surface, uint16_t nXDst, uint16_t nYDst, u
|
||||
|
||||
if ((textWidth > 0) && (textHeight > 0))
|
||||
{
|
||||
fillWidth = nWidth - (ninePatch->width - ninePatch->fillWidth);
|
||||
fillHeight = nHeight - (ninePatch->height - ninePatch->fillHeight);
|
||||
const int fwd = (ninePatch->width - ninePatch->fillWidth);
|
||||
const int fhd = (ninePatch->height - ninePatch->fillHeight);
|
||||
|
||||
offsetX = ninePatch->fillLeft;
|
||||
offsetY = ninePatch->fillTop;
|
||||
uint16_t fillWidth = nWidth - WINPR_ASSERTING_INT_CAST(uint16_t, fwd);
|
||||
uint16_t fillHeight = nHeight - WINPR_ASSERTING_INT_CAST(uint16_t, fhd);
|
||||
uint16_t offsetX = WINPR_ASSERTING_INT_CAST(uint16_t, ninePatch->fillLeft);
|
||||
uint16_t offsetY = WINPR_ASSERTING_INT_CAST(uint16_t, ninePatch->fillTop);
|
||||
|
||||
if (textWidth < fillWidth)
|
||||
offsetX = ((fillWidth - textWidth) / 2) + ninePatch->fillLeft;
|
||||
{
|
||||
const int wd = ((fillWidth - textWidth) / 2) + ninePatch->fillLeft;
|
||||
offsetX = WINPR_ASSERTING_INT_CAST(uint16_t, wd);
|
||||
}
|
||||
else if (textWidth < ninePatch->width)
|
||||
offsetX = ((ninePatch->width - textWidth) / 2);
|
||||
{
|
||||
const int wd = ((ninePatch->width - textWidth) / 2);
|
||||
offsetX = WINPR_ASSERTING_INT_CAST(uint16_t, wd);
|
||||
}
|
||||
|
||||
if (textHeight < fillHeight)
|
||||
offsetY = ((fillHeight - textHeight) / 2) + ninePatch->fillTop;
|
||||
{
|
||||
const int wd = ((fillHeight - textHeight) / 2) + ninePatch->fillTop;
|
||||
offsetY = WINPR_ASSERTING_INT_CAST(uint16_t, wd);
|
||||
}
|
||||
else if (textHeight < ninePatch->height)
|
||||
offsetY = ((ninePatch->height - textHeight) / 2);
|
||||
{
|
||||
const int wd = ((ninePatch->height - textHeight) / 2);
|
||||
offsetY = WINPR_ASSERTING_INT_CAST(uint16_t, wd);
|
||||
}
|
||||
|
||||
rdtk_font_draw_text(surface, nXDst + offsetX, nYDst + offsetY, font, text);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user