rdtk: Fixed warnings, added assertions

This commit is contained in:
Armin Novak 2021-06-18 10:01:52 +02:00 committed by akallabeth
parent cbb39709b9
commit 0b0b716dd6
14 changed files with 170 additions and 139 deletions

View File

@ -19,14 +19,9 @@
#ifndef RDTK_H #ifndef RDTK_H
#define RDTK_H #define RDTK_H
#include <stdint.h>
#include <rdtk/api.h> #include <rdtk/api.h>
#include <winpr/crt.h>
#include <winpr/windows.h>
#include <freerdp/codec/color.h>
#include <freerdp/codec/region.h>
typedef struct rdtk_engine rdtkEngine; typedef struct rdtk_engine rdtkEngine;
typedef struct rdtk_font rdtkFont; typedef struct rdtk_font rdtkFont;
typedef struct rdtk_glyph rdtkGlyph; typedef struct rdtk_glyph rdtkGlyph;
@ -43,38 +38,40 @@ extern "C"
/* Engine */ /* Engine */
RDTK_EXPORT rdtkEngine* rdtk_engine_new(); RDTK_EXPORT rdtkEngine* rdtk_engine_new(void);
RDTK_EXPORT void rdtk_engine_free(rdtkEngine* engine); RDTK_EXPORT void rdtk_engine_free(rdtkEngine* engine);
/* Surface */ /* Surface */
RDTK_EXPORT int rdtk_surface_fill(rdtkSurface* surface, int x, int y, int width, int height, RDTK_EXPORT int rdtk_surface_fill(rdtkSurface* surface, uint16_t x, uint16_t y, uint16_t width,
UINT32 color); uint16_t height, uint32_t color);
RDTK_EXPORT rdtkSurface* rdtk_surface_new(rdtkEngine* engine, BYTE* data, int width, int height, RDTK_EXPORT rdtkSurface* rdtk_surface_new(rdtkEngine* engine, uint8_t* data, uint16_t width,
int scanline); uint16_t height, uint32_t scanline);
RDTK_EXPORT void rdtk_surface_free(rdtkSurface* surface); RDTK_EXPORT void rdtk_surface_free(rdtkSurface* surface);
/* Font */ /* Font */
RDTK_EXPORT int rdtk_font_draw_text(rdtkSurface* surface, int nXDst, int nYDst, rdtkFont* font, RDTK_EXPORT int rdtk_font_draw_text(rdtkSurface* surface, uint16_t nXDst, uint16_t nYDst,
const char* text); rdtkFont* font, const char* text);
/* Button */ /* Button */
RDTK_EXPORT int rdtk_button_draw(rdtkSurface* surface, int nXDst, int nYDst, int nWidth, RDTK_EXPORT int rdtk_button_draw(rdtkSurface* surface, uint16_t nXDst, uint16_t nYDst,
int nHeight, rdtkButton* button, const char* text); uint16_t nWidth, uint16_t nHeight, rdtkButton* button,
const char* text);
/* Label */ /* Label */
RDTK_EXPORT int rdtk_label_draw(rdtkSurface* surface, int nXDst, int nYDst, int nWidth, RDTK_EXPORT int rdtk_label_draw(rdtkSurface* surface, uint16_t nXDst, uint16_t nYDst,
int nHeight, rdtkLabel* label, const char* text, int hAlign, uint16_t nWidth, uint16_t nHeight, rdtkLabel* label,
int vAlign); const char* text, uint16_t hAlign, uint16_t vAlign);
/* TextField */ /* TextField */
RDTK_EXPORT int rdtk_text_field_draw(rdtkSurface* surface, int nXDst, int nYDst, int nWidth, RDTK_EXPORT int rdtk_text_field_draw(rdtkSurface* surface, uint16_t nXDst, uint16_t nYDst,
int nHeight, rdtkTextField* textField, const char* text); uint16_t nWidth, uint16_t nHeight,
rdtkTextField* textField, const char* text);
#ifdef __cplusplus #ifdef __cplusplus
} }

View File

@ -24,15 +24,15 @@
#include "rdtk_button.h" #include "rdtk_button.h"
int rdtk_button_draw(rdtkSurface* surface, int nXDst, int nYDst, int nWidth, int nHeight, int rdtk_button_draw(rdtkSurface* surface, uint16_t nXDst, uint16_t nYDst, uint16_t nWidth,
rdtkButton* button, const char* text) uint16_t nHeight, rdtkButton* button, const char* text)
{ {
int offsetX; uint16_t offsetX;
int offsetY; uint16_t offsetY;
int textWidth; uint16_t textWidth;
int textHeight; uint16_t textHeight;
int fillWidth; uint16_t fillWidth;
int fillHeight; uint16_t fillHeight;
rdtkFont* font; rdtkFont* font;
rdtkEngine* engine; rdtkEngine* engine;
rdtkNinePatch* ninePatch; rdtkNinePatch* ninePatch;

View File

@ -44,11 +44,11 @@ static int rdtk_font_draw_glyph(rdtkSurface* surface, int nXDst, int nYDst, rdtk
int nHeight; int nHeight;
int nSrcStep; int nSrcStep;
int nDstStep; int nDstStep;
BYTE* pSrcData; uint8_t* pSrcData;
BYTE* pSrcPixel; uint8_t* pSrcPixel;
BYTE* pDstData; uint8_t* pDstData;
BYTE* pDstPixel; uint8_t* pDstPixel;
BYTE A, R, G, B; uint8_t A, R, G, B;
nXDst += glyph->offsetX; nXDst += glyph->offsetX;
nYDst += glyph->offsetY; nYDst += glyph->offsetY;
nXSrc = glyph->rectX; nXSrc = glyph->rectX;
@ -105,7 +105,7 @@ static int rdtk_font_draw_glyph(rdtkSurface* surface, int nXDst, int nYDst, rdtk
return 1; return 1;
} }
int rdtk_font_draw_text(rdtkSurface* surface, int nXDst, int nYDst, rdtkFont* font, int rdtk_font_draw_text(rdtkSurface* surface, uint16_t nXDst, uint16_t nYDst, rdtkFont* font,
const char* text) const char* text)
{ {
size_t index; size_t index;
@ -124,11 +124,11 @@ int rdtk_font_draw_text(rdtkSurface* surface, int nXDst, int nYDst, rdtkFont* fo
return 1; return 1;
} }
int rdtk_font_text_draw_size(rdtkFont* font, int* width, int* height, const char* text) int rdtk_font_text_draw_size(rdtkFont* font, uint16_t* width, uint16_t* height, const char* text)
{ {
size_t index; size_t index;
size_t length; size_t length;
int glyphIndex; size_t glyphIndex;
rdtkGlyph* glyph; rdtkGlyph* glyph;
*width = 0; *width = 0;
*height = 0; *height = 0;
@ -149,28 +149,32 @@ int rdtk_font_text_draw_size(rdtkFont* font, int* width, int* height, const char
return 1; return 1;
} }
static char* rdtk_font_load_descriptor_file(const char* filename, int* pSize) static char* rdtk_font_load_descriptor_file(const char* filename, size_t* pSize)
{ {
BYTE* buffer; uint8_t* buffer;
FILE* fp = NULL; FILE* fp = NULL;
size_t readSize; size_t readSize;
size_t fileSize; union
{
size_t s;
INT64 i64;
} fileSize;
fp = winpr_fopen(filename, "r"); fp = winpr_fopen(filename, "r");
if (!fp) if (!fp)
return NULL; return NULL;
_fseeki64(fp, 0, SEEK_END); _fseeki64(fp, 0, SEEK_END);
fileSize = _ftelli64(fp); fileSize.i64 = _ftelli64(fp);
_fseeki64(fp, 0, SEEK_SET); _fseeki64(fp, 0, SEEK_SET);
if (fileSize < 1) if (fileSize.i64 < 1)
{ {
fclose(fp); fclose(fp);
return NULL; return NULL;
} }
buffer = (BYTE*)malloc(fileSize + 2); buffer = (uint8_t*)malloc(fileSize.s + 2);
if (!buffer) if (!buffer)
{ {
@ -178,12 +182,12 @@ static char* rdtk_font_load_descriptor_file(const char* filename, int* pSize)
return NULL; return NULL;
} }
readSize = fread(buffer, fileSize, 1, fp); readSize = fread(buffer, fileSize.s, 1, fp);
if (!readSize) if (readSize == 0)
{ {
if (!ferror(fp)) if (!ferror(fp))
readSize = fileSize; readSize = fileSize.s;
} }
fclose(fp); fclose(fp);
@ -194,16 +198,16 @@ static char* rdtk_font_load_descriptor_file(const char* filename, int* pSize)
return NULL; return NULL;
} }
buffer[fileSize] = '\0'; buffer[fileSize.s] = '\0';
buffer[fileSize + 1] = '\0'; buffer[fileSize.s + 1] = '\0';
*pSize = (int)fileSize; *pSize = fileSize.s;
return (char*)buffer; return (char*)buffer;
} }
static int rdtk_font_convert_descriptor_code_to_utf8(const char* str, BYTE* utf8) static int rdtk_font_convert_descriptor_code_to_utf8(const char* str, uint8_t* utf8)
{ {
size_t len = strlen(str); size_t len = strlen(str);
*((UINT32*)utf8) = 0; *((uint32_t*)utf8) = 0;
if (len < 1) if (len < 1)
return 1; return 1;
@ -235,7 +239,7 @@ static int rdtk_font_convert_descriptor_code_to_utf8(const char* str, BYTE* utf8
return 1; return 1;
} }
static int rdtk_font_parse_descriptor_buffer(rdtkFont* font, BYTE* buffer, int size) static int rdtk_font_parse_descriptor_buffer(rdtkFont* font, uint8_t* buffer, size_t size)
{ {
char* p; char* p;
char* q; char* q;
@ -576,15 +580,16 @@ static int rdtk_font_parse_descriptor_buffer(rdtkFont* font, BYTE* buffer, int s
static int rdtk_font_load_descriptor(rdtkFont* font, const char* filename) static int rdtk_font_load_descriptor(rdtkFont* font, const char* filename)
{ {
int size; size_t size;
char* buffer; char* buffer;
buffer = rdtk_font_load_descriptor_file(filename, &size); buffer = rdtk_font_load_descriptor_file(filename, &size);
if (!buffer) if (!buffer)
return -1; return -1;
return rdtk_font_parse_descriptor_buffer(font, (BYTE*)buffer, size); return rdtk_font_parse_descriptor_buffer(font, (uint8_t*)buffer, size);
} }
rdtkFont* rdtk_font_new(rdtkEngine* engine, const char* path, const char* file) rdtkFont* rdtk_font_new(rdtkEngine* engine, const char* path, const char* file)
{ {
int status; int status;
@ -658,12 +663,14 @@ cleanup:
return NULL; return NULL;
} }
static rdtkFont* rdtk_embedded_font_new(rdtkEngine* engine, BYTE* imageData, int imageSize,
BYTE* descriptorData, int descriptorSize) static rdtkFont* rdtk_embedded_font_new(rdtkEngine* engine, const uint8_t* imageData,
size_t imageSize, const uint8_t* descriptorData,
size_t descriptorSize)
{ {
int size; size_t size;
int status; int status;
BYTE* buffer; uint8_t* buffer;
rdtkFont* font; rdtkFont* font;
font = (rdtkFont*)calloc(1, sizeof(rdtkFont)); font = (rdtkFont*)calloc(1, sizeof(rdtkFont));
@ -689,7 +696,7 @@ static rdtkFont* rdtk_embedded_font_new(rdtkEngine* engine, BYTE* imageData, int
} }
size = descriptorSize; size = descriptorSize;
buffer = (BYTE*)malloc(size); buffer = (uint8_t*)malloc(size);
if (!buffer) if (!buffer)
{ {
@ -726,10 +733,10 @@ int rdtk_font_engine_init(rdtkEngine* engine)
{ {
if (!engine->font) if (!engine->font)
{ {
int imageSize; SSIZE_T imageSize;
int descriptorSize; SSIZE_T descriptorSize;
BYTE* imageData = NULL; const uint8_t* imageData = NULL;
BYTE* descriptorData = NULL; const uint8_t* descriptorData = NULL;
imageSize = rdtk_get_embedded_resource_file("source_serif_pro_regular_12.png", &imageData); imageSize = rdtk_get_embedded_resource_file("source_serif_pro_regular_12.png", &imageData);
descriptorSize = descriptorSize =
rdtk_get_embedded_resource_file("source_serif_pro_regular_12.xml", &descriptorData); rdtk_get_embedded_resource_file("source_serif_pro_regular_12.xml", &descriptorData);
@ -737,8 +744,8 @@ int rdtk_font_engine_init(rdtkEngine* engine)
if ((imageSize < 0) || (descriptorSize < 0)) if ((imageSize < 0) || (descriptorSize < 0))
return -1; return -1;
engine->font = engine->font = rdtk_embedded_font_new(engine, imageData, (size_t)imageSize, descriptorData,
rdtk_embedded_font_new(engine, imageData, imageSize, descriptorData, descriptorSize); (size_t)descriptorSize);
} }
return 1; return 1;

View File

@ -19,10 +19,10 @@
#ifndef RDTK_FONT_PRIVATE_H #ifndef RDTK_FONT_PRIVATE_H
#define RDTK_FONT_PRIVATE_H #define RDTK_FONT_PRIVATE_H
#include <stdint.h>
#include <rdtk/rdtk.h> #include <rdtk/rdtk.h>
#include <winpr/crt.h>
#include <winpr/synch.h>
#include <winpr/image.h> #include <winpr/image.h>
#include "rdtk_engine.h" #include "rdtk_engine.h"
@ -36,19 +36,19 @@ struct rdtk_glyph
int rectY; int rectY;
int rectWidth; int rectWidth;
int rectHeight; int rectHeight;
BYTE code[4]; uint8_t code[4];
}; };
struct rdtk_font struct rdtk_font
{ {
rdtkEngine* engine; rdtkEngine* engine;
int size; uint32_t size;
int height; uint16_t height;
char* family; char* family;
char* style; char* style;
wImage* image; wImage* image;
int glyphCount; uint16_t glyphCount;
rdtkGlyph* glyphs; rdtkGlyph* glyphs;
}; };
@ -57,7 +57,8 @@ extern "C"
{ {
#endif #endif
int rdtk_font_text_draw_size(rdtkFont* font, int* width, int* height, const char* text); int rdtk_font_text_draw_size(rdtkFont* font, uint16_t* width, uint16_t* height,
const char* text);
int rdtk_font_engine_init(rdtkEngine* engine); int rdtk_font_engine_init(rdtkEngine* engine);
int rdtk_font_engine_uninit(rdtkEngine* engine); int rdtk_font_engine_uninit(rdtkEngine* engine);

View File

@ -24,13 +24,14 @@
#include "rdtk_label.h" #include "rdtk_label.h"
int rdtk_label_draw(rdtkSurface* surface, int nXDst, int nYDst, int nWidth, int nHeight, int rdtk_label_draw(rdtkSurface* surface, uint16_t nXDst, uint16_t nYDst, uint16_t nWidth,
rdtkLabel* label, const char* text, int hAlign, int vAlign) uint16_t nHeight, rdtkLabel* label, const char* text, uint16_t hAlign,
uint16_t vAlign)
{ {
int offsetX; uint16_t offsetX;
int offsetY; uint16_t offsetY;
int textWidth; uint16_t textWidth;
int textHeight; uint16_t textHeight;
rdtkFont* font; rdtkFont* font;
rdtkEngine* engine; rdtkEngine* engine;

View File

@ -20,23 +20,21 @@
#include "config.h" #include "config.h"
#endif #endif
#include <freerdp/codec/color.h>
#include "rdtk_resources.h" #include "rdtk_resources.h"
#include "rdtk_nine_patch.h" #include "rdtk_nine_patch.h"
static int rdtk_image_copy_alpha_blend(BYTE* pDstData, int nDstStep, int nXDst, int nYDst, static int rdtk_image_copy_alpha_blend(uint8_t* pDstData, int nDstStep, int nXDst, int nYDst,
int nWidth, int nHeight, BYTE* pSrcData, int nSrcStep, int nWidth, int nHeight, uint8_t* pSrcData, int nSrcStep,
int nXSrc, int nYSrc) int nXSrc, int nYSrc)
{ {
int x, y; int x, y;
BYTE A, R, G, B; uint8_t A, R, G, B;
for (y = 0; y < nHeight; y++) for (y = 0; y < nHeight; y++)
{ {
const BYTE* pSrcPixel = &pSrcData[((nYSrc + y) * nSrcStep) + (nXSrc * 4)]; const uint8_t* pSrcPixel = &pSrcData[((nYSrc + y) * nSrcStep) + (nXSrc * 4)];
BYTE* pDstPixel = &pDstData[((nYDst + y) * nDstStep) + (nXDst * 4)]; uint8_t* pDstPixel = &pDstData[((nYDst + y) * nDstStep) + (nXDst * 4)];
for (x = 0; x < nWidth; x++) for (x = 0; x < nWidth; x++)
{ {
@ -80,8 +78,8 @@ int rdtk_nine_patch_draw(rdtkSurface* surface, int nXDst, int nYDst, int nWidth,
int nYSrc; int nYSrc;
int nSrcStep; int nSrcStep;
int nDstStep; int nDstStep;
BYTE* pSrcData; uint8_t* pSrcData;
BYTE* pDstData; uint8_t* pDstData;
int scaleWidth; int scaleWidth;
if (nWidth < ninePatch->width) if (nWidth < ninePatch->width)
@ -206,10 +204,10 @@ int rdtk_nine_patch_draw(rdtkSurface* surface, int nXDst, int nYDst, int nWidth,
int rdtk_nine_patch_set_image(rdtkNinePatch* ninePatch, wImage* image) int rdtk_nine_patch_set_image(rdtkNinePatch* ninePatch, wImage* image)
{ {
int x, y; int x, y;
BYTE* data; uint8_t* data;
int beg, end; int beg, end;
int scanline; int scanline;
UINT32* pixel; uint32_t* pixel;
int width, height; int width, height;
ninePatch->image = image; ninePatch->image = image;
width = image->width; width = image->width;
@ -218,7 +216,7 @@ int rdtk_nine_patch_set_image(rdtkNinePatch* ninePatch, wImage* image)
data = image->data; data = image->data;
/* parse scalable area */ /* parse scalable area */
beg = end = -1; beg = end = -1;
pixel = (UINT32*)&data[4]; /* (1, 0) */ pixel = (uint32_t*)&data[4]; /* (1, 0) */
for (x = 1; x < width - 1; x++) for (x = 1; x < width - 1; x++)
{ {
@ -245,7 +243,7 @@ int rdtk_nine_patch_set_image(rdtkNinePatch* ninePatch, wImage* image)
ninePatch->scaleRight = end - 1; ninePatch->scaleRight = end - 1;
ninePatch->scaleWidth = ninePatch->scaleRight - ninePatch->scaleLeft; ninePatch->scaleWidth = ninePatch->scaleRight - ninePatch->scaleLeft;
beg = end = -1; beg = end = -1;
pixel = (UINT32*)&data[scanline]; /* (0, 1) */ pixel = (uint32_t*)&data[scanline]; /* (0, 1) */
for (y = 1; y < height - 1; y++) for (y = 1; y < height - 1; y++)
{ {
@ -265,7 +263,7 @@ int rdtk_nine_patch_set_image(rdtkNinePatch* ninePatch, wImage* image)
} }
} }
pixel = (UINT32*)&((BYTE*)pixel)[scanline]; pixel = (uint32_t*)&((uint8_t*)pixel)[scanline];
} }
ninePatch->scaleTop = beg - 1; ninePatch->scaleTop = beg - 1;
@ -273,7 +271,7 @@ int rdtk_nine_patch_set_image(rdtkNinePatch* ninePatch, wImage* image)
ninePatch->scaleHeight = ninePatch->scaleBottom - ninePatch->scaleTop; ninePatch->scaleHeight = ninePatch->scaleBottom - ninePatch->scaleTop;
/* parse fillable area */ /* parse fillable area */
beg = end = -1; beg = end = -1;
pixel = (UINT32*)&data[((height - 1) * scanline) + 4]; /* (1, height - 1) */ pixel = (uint32_t*)&data[((height - 1) * scanline) + 4]; /* (1, height - 1) */
for (x = 1; x < width - 1; x++) for (x = 1; x < width - 1; x++)
{ {
@ -300,7 +298,7 @@ int rdtk_nine_patch_set_image(rdtkNinePatch* ninePatch, wImage* image)
ninePatch->fillRight = end - 1; ninePatch->fillRight = end - 1;
ninePatch->fillWidth = ninePatch->fillRight - ninePatch->fillLeft; ninePatch->fillWidth = ninePatch->fillRight - ninePatch->fillLeft;
beg = end = -1; beg = end = -1;
pixel = (UINT32*)&data[((width - 1) * 4) + scanline]; /* (width - 1, 1) */ pixel = (uint32_t*)&data[((width - 1) * 4) + scanline]; /* (width - 1, 1) */
for (y = 1; y < height - 1; y++) for (y = 1; y < height - 1; y++)
{ {
@ -320,7 +318,7 @@ int rdtk_nine_patch_set_image(rdtkNinePatch* ninePatch, wImage* image)
} }
} }
pixel = (UINT32*)&((BYTE*)pixel)[scanline]; pixel = (uint32_t*)&((uint8_t*)pixel)[scanline];
} }
ninePatch->fillTop = beg - 1; ninePatch->fillTop = beg - 1;
@ -372,8 +370,8 @@ int rdtk_nine_patch_engine_init(rdtkEngine* engine)
if (!engine->button9patch) if (!engine->button9patch)
{ {
int size; SSIZE_T size;
BYTE* data; const uint8_t* data;
status = -1; status = -1;
size = rdtk_get_embedded_resource_file("btn_default_normal.9.png", &data); size = rdtk_get_embedded_resource_file("btn_default_normal.9.png", &data);
@ -382,7 +380,7 @@ int rdtk_nine_patch_engine_init(rdtkEngine* engine)
image = winpr_image_new(); image = winpr_image_new();
if (image) if (image)
status = winpr_image_read_buffer(image, data, size); status = winpr_image_read_buffer(image, data, (size_t)size);
} }
if (status > 0) if (status > 0)
@ -400,8 +398,8 @@ int rdtk_nine_patch_engine_init(rdtkEngine* engine)
if (!engine->textField9patch) if (!engine->textField9patch)
{ {
int size; SSIZE_T size;
BYTE* data; const uint8_t* data;
status = -1; status = -1;
size = rdtk_get_embedded_resource_file("textfield_default.9.png", &data); size = rdtk_get_embedded_resource_file("textfield_default.9.png", &data);
image = NULL; image = NULL;
@ -411,7 +409,7 @@ int rdtk_nine_patch_engine_init(rdtkEngine* engine)
image = winpr_image_new(); image = winpr_image_new();
if (image) if (image)
status = winpr_image_read_buffer(image, data, size); status = winpr_image_read_buffer(image, data, (size_t)size);
} }
if (status > 0) if (status > 0)

View File

@ -19,6 +19,7 @@
#ifndef RDTK_NINE_PATCH_PRIVATE_H #ifndef RDTK_NINE_PATCH_PRIVATE_H
#define RDTK_NINE_PATCH_PRIVATE_H #define RDTK_NINE_PATCH_PRIVATE_H
#include <stdint.h>
#include <rdtk/rdtk.h> #include <rdtk/rdtk.h>
#include <winpr/image.h> #include <winpr/image.h>
@ -36,7 +37,7 @@ struct rdtk_nine_patch
int width; int width;
int height; int height;
int scanline; int scanline;
BYTE* data; uint8_t* data;
int scaleLeft; int scaleLeft;
int scaleRight; int scaleRight;

View File

@ -20,11 +20,13 @@
#include "config.h" #include "config.h"
#endif #endif
#include <stdint.h>
#include <string.h>
#include "rdtk_resources.h" #include "rdtk_resources.h"
/* Nine Patches */ /* Nine Patches */
static BYTE btn_default_normal_9_png[] = { static const uint8_t btn_default_normal_9_png[] = {
0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a, 0x00, 0x00, 0x00, 0x0d, 0x49, 0x48, 0x44, 0x52, 0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a, 0x00, 0x00, 0x00, 0x0d, 0x49, 0x48, 0x44, 0x52,
0x00, 0x00, 0x00, 0x1a, 0x00, 0x00, 0x00, 0x32, 0x08, 0x06, 0x00, 0x00, 0x00, 0x42, 0xb5, 0xcb, 0x00, 0x00, 0x00, 0x1a, 0x00, 0x00, 0x00, 0x32, 0x08, 0x06, 0x00, 0x00, 0x00, 0x42, 0xb5, 0xcb,
0x95, 0x00, 0x00, 0x00, 0x09, 0x70, 0x48, 0x59, 0x73, 0x00, 0x00, 0x0b, 0x89, 0x00, 0x00, 0x0b, 0x95, 0x00, 0x00, 0x00, 0x09, 0x70, 0x48, 0x59, 0x73, 0x00, 0x00, 0x0b, 0x89, 0x00, 0x00, 0x0b,
@ -69,9 +71,9 @@ static BYTE btn_default_normal_9_png[] = {
0x26, 0xfe, 0xd3, 0x50, 0x44, 0xf0, 0x17, 0xa0, 0xb1, 0xe0, 0x73, 0xc3, 0xe6, 0x24, 0xdb, 0x00, 0x26, 0xfe, 0xd3, 0x50, 0x44, 0xf0, 0x17, 0xa0, 0xb1, 0xe0, 0x73, 0xc3, 0xe6, 0x24, 0xdb, 0x00,
0x00, 0x00, 0x00, 0x49, 0x45, 0x4e, 0x44, 0xae, 0x42, 0x60, 0x82 0x00, 0x00, 0x00, 0x49, 0x45, 0x4e, 0x44, 0xae, 0x42, 0x60, 0x82
}; };
static int btn_default_normal_9_png_len = 683; static const int btn_default_normal_9_png_len = 683;
static BYTE textfield_default_9_png[] = { static const uint8_t textfield_default_9_png[] = {
0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a, 0x00, 0x00, 0x00, 0x0d, 0x49, 0x48, 0x44, 0x52, 0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a, 0x00, 0x00, 0x00, 0x0d, 0x49, 0x48, 0x44, 0x52,
0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x32, 0x08, 0x06, 0x00, 0x00, 0x00, 0x46, 0x40, 0x1b, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x32, 0x08, 0x06, 0x00, 0x00, 0x00, 0x46, 0x40, 0x1b,
0xa8, 0x00, 0x00, 0x00, 0x09, 0x70, 0x48, 0x59, 0x73, 0x00, 0x00, 0x0b, 0x89, 0x00, 0x00, 0x0b, 0xa8, 0x00, 0x00, 0x00, 0x09, 0x70, 0x48, 0x59, 0x73, 0x00, 0x00, 0x0b, 0x89, 0x00, 0x00, 0x0b,
@ -100,11 +102,11 @@ static BYTE textfield_default_9_png[] = {
0x71, 0x3a, 0x69, 0xd1, 0x87, 0x00, 0x00, 0x00, 0x00, 0x49, 0x45, 0x4e, 0x44, 0xae, 0x42, 0x60, 0x71, 0x3a, 0x69, 0xd1, 0x87, 0x00, 0x00, 0x00, 0x00, 0x49, 0x45, 0x4e, 0x44, 0xae, 0x42, 0x60,
0x82 0x82
}; };
static int textfield_default_9_png_len = 417; static const int textfield_default_9_png_len = 417;
/* Fonts */ /* Fonts */
static BYTE source_serif_pro_regular_12_png[] = { static const uint8_t source_serif_pro_regular_12_png[] = {
0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a, 0x00, 0x00, 0x00, 0x0d, 0x49, 0x48, 0x44, 0x52, 0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a, 0x00, 0x00, 0x00, 0x0d, 0x49, 0x48, 0x44, 0x52,
0x00, 0x00, 0x02, 0xe7, 0x00, 0x00, 0x00, 0x11, 0x08, 0x06, 0x00, 0x00, 0x00, 0x7e, 0x53, 0x02, 0x00, 0x00, 0x02, 0xe7, 0x00, 0x00, 0x00, 0x11, 0x08, 0x06, 0x00, 0x00, 0x00, 0x7e, 0x53, 0x02,
0xe5, 0x00, 0x00, 0x00, 0x04, 0x73, 0x42, 0x49, 0x54, 0x08, 0x08, 0x08, 0x08, 0x7c, 0x08, 0x64, 0xe5, 0x00, 0x00, 0x00, 0x04, 0x73, 0x42, 0x49, 0x54, 0x08, 0x08, 0x08, 0x08, 0x7c, 0x08, 0x64,
@ -628,9 +630,9 @@ static BYTE source_serif_pro_regular_12_png[] = {
0x1f, 0x5a, 0x3b, 0xf9, 0xfc, 0xc1, 0xff, 0x01, 0xf4, 0x4f, 0x9a, 0x26, 0x12, 0xca, 0xbf, 0xd8, 0x1f, 0x5a, 0x3b, 0xf9, 0xfc, 0xc1, 0xff, 0x01, 0xf4, 0x4f, 0x9a, 0x26, 0x12, 0xca, 0xbf, 0xd8,
0x00, 0x00, 0x00, 0x00, 0x49, 0x45, 0x4e, 0x44, 0xae, 0x42, 0x60, 0x82 0x00, 0x00, 0x00, 0x00, 0x49, 0x45, 0x4e, 0x44, 0xae, 0x42, 0x60, 0x82
}; };
static int source_serif_pro_regular_12_png_len = 8348; static const int source_serif_pro_regular_12_png_len = 8348;
static BYTE source_serif_pro_regular_12_xml[] = { static const uint8_t source_serif_pro_regular_12_xml[] = {
0x3c, 0x3f, 0x78, 0x6d, 0x6c, 0x20, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x3d, 0x22, 0x31, 0x3c, 0x3f, 0x78, 0x6d, 0x6c, 0x20, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x3d, 0x22, 0x31,
0x2e, 0x30, 0x22, 0x20, 0x65, 0x6e, 0x63, 0x6f, 0x64, 0x69, 0x6e, 0x67, 0x3d, 0x22, 0x75, 0x74, 0x2e, 0x30, 0x22, 0x20, 0x65, 0x6e, 0x63, 0x6f, 0x64, 0x69, 0x6e, 0x67, 0x3d, 0x22, 0x75, 0x74,
0x66, 0x2d, 0x38, 0x22, 0x3f, 0x3e, 0x0a, 0x3c, 0x46, 0x6f, 0x6e, 0x74, 0x20, 0x73, 0x69, 0x7a, 0x66, 0x2d, 0x38, 0x22, 0x3f, 0x3e, 0x0a, 0x3c, 0x46, 0x6f, 0x6e, 0x74, 0x20, 0x73, 0x69, 0x7a,
@ -992,7 +994,7 @@ static BYTE source_serif_pro_regular_12_xml[] = {
0x37, 0x33, 0x36, 0x20, 0x36, 0x20, 0x37, 0x20, 0x33, 0x22, 0x20, 0x63, 0x6f, 0x64, 0x65, 0x3d, 0x37, 0x33, 0x36, 0x20, 0x36, 0x20, 0x37, 0x20, 0x33, 0x22, 0x20, 0x63, 0x6f, 0x64, 0x65, 0x3d,
0x22, 0x7e, 0x22, 0x2f, 0x3e, 0x0a, 0x3c, 0x2f, 0x46, 0x6f, 0x6e, 0x74, 0x3e, 0x0a 0x22, 0x7e, 0x22, 0x2f, 0x3e, 0x0a, 0x3c, 0x2f, 0x46, 0x6f, 0x6e, 0x74, 0x3e, 0x0a
}; };
static int source_serif_pro_regular_12_xml_len = 5758; static const int source_serif_pro_regular_12_xml_len = 5758;
/** /**
* Bitmap fonts were generated using FontBuilder on Windows with the following settings: * Bitmap fonts were generated using FontBuilder on Windows with the following settings:
@ -1006,7 +1008,7 @@ static int source_serif_pro_regular_12_xml_len = 5758;
* These embedded resources were converted from binaries files to C arrays using "xxd -i" * These embedded resources were converted from binaries files to C arrays using "xxd -i"
*/ */
int rdtk_get_embedded_resource_file(const char* filename, BYTE** pData) SSIZE_T rdtk_get_embedded_resource_file(const char* filename, const uint8_t** pData)
{ {
if (strcmp(filename, "source_serif_pro_regular_12.png") == 0) if (strcmp(filename, "source_serif_pro_regular_12.png") == 0)
{ {

View File

@ -19,6 +19,7 @@
#ifndef RDTK_RESOURCES_PRIVATE_H #ifndef RDTK_RESOURCES_PRIVATE_H
#define RDTK_RESOURCES_PRIVATE_H #define RDTK_RESOURCES_PRIVATE_H
#include <stdint.h>
#include <rdtk/rdtk.h> #include <rdtk/rdtk.h>
#include "rdtk_engine.h" #include "rdtk_engine.h"
@ -28,7 +29,7 @@ extern "C"
{ {
#endif #endif
int rdtk_get_embedded_resource_file(const char* filename, BYTE** pData); SSIZE_T rdtk_get_embedded_resource_file(const char* filename, const uint8_t** pData);
#ifdef __cplusplus #ifdef __cplusplus
} }

View File

@ -22,15 +22,28 @@
#include "rdtk_surface.h" #include "rdtk_surface.h"
int rdtk_surface_fill(rdtkSurface* surface, int x, int y, int width, int height, UINT32 color) #include <string.h>
int rdtk_surface_fill(rdtkSurface* surface, uint16_t x, uint16_t y, uint16_t width, uint16_t height,
uint32_t color)
{ {
freerdp_image_fill(surface->data, PIXEL_FORMAT_XRGB32, surface->scanline, x, y, width, height, uint16_t i;
color); for (i = y; x < y + height; i++)
{
uint16_t j;
uint8_t* line = &surface->data[i * surface->scanline];
for (j = x; j < x + width; x++)
{
uint32_t* pixel = (uint32_t*)&line[x + 4];
*pixel = color;
}
}
return 1; return 1;
} }
rdtkSurface* rdtk_surface_new(rdtkEngine* engine, BYTE* data, int width, int height, int scanline) rdtkSurface* rdtk_surface_new(rdtkEngine* engine, uint8_t* data, uint16_t width, uint16_t height,
uint32_t scanline)
{ {
rdtkSurface* surface; rdtkSurface* surface;
@ -50,13 +63,13 @@ rdtkSurface* rdtk_surface_new(rdtkEngine* engine, BYTE* data, int width, int hei
surface->scanline = scanline; surface->scanline = scanline;
surface->data = data; surface->data = data;
surface->owner = FALSE; surface->owner = false;
if (!data) if (!data)
{ {
surface->scanline = (surface->width + (surface->width % 4)) * 4; surface->scanline = (surface->width + (surface->width % 4)) * 4;
surface->data = (BYTE*)calloc(surface->height, surface->scanline); surface->data = (uint8_t*)calloc(surface->height, surface->scanline);
if (!surface->data) if (!surface->data)
{ {
@ -64,9 +77,9 @@ rdtkSurface* rdtk_surface_new(rdtkEngine* engine, BYTE* data, int width, int hei
return NULL; return NULL;
} }
ZeroMemory(surface->data, surface->scanline * surface->height); memset(surface->data, 0, surface->scanline * surface->height);
surface->owner = TRUE; surface->owner = true;
} }
return surface; return surface;

View File

@ -19,6 +19,8 @@
#ifndef RDTK_SURFACE_PRIVATE_H #ifndef RDTK_SURFACE_PRIVATE_H
#define RDTK_SURFACE_PRIVATE_H #define RDTK_SURFACE_PRIVATE_H
#include <stdint.h>
#include <stdbool.h>
#include <rdtk/rdtk.h> #include <rdtk/rdtk.h>
#include "rdtk_engine.h" #include "rdtk_engine.h"
@ -27,10 +29,10 @@ struct rdtk_surface
{ {
rdtkEngine* engine; rdtkEngine* engine;
int width; uint16_t width;
int height; uint16_t height;
int scanline; uint32_t scanline;
BYTE* data; uint8_t* data;
BOOL owner; bool owner;
}; };
#endif /* RDTK_SURFACE_PRIVATE_H */ #endif /* RDTK_SURFACE_PRIVATE_H */

View File

@ -24,15 +24,15 @@
#include "rdtk_text_field.h" #include "rdtk_text_field.h"
int rdtk_text_field_draw(rdtkSurface* surface, int nXDst, int nYDst, int nWidth, int nHeight, int rdtk_text_field_draw(rdtkSurface* surface, uint16_t nXDst, uint16_t nYDst, uint16_t nWidth,
rdtkTextField* textField, const char* text) uint16_t nHeight, rdtkTextField* textField, const char* text)
{ {
int offsetX; uint16_t offsetX;
int offsetY; uint16_t offsetY;
int textWidth; uint16_t textWidth;
int textHeight; uint16_t textHeight;
int fillWidth; uint16_t fillWidth;
int fillHeight; uint16_t fillHeight;
rdtkFont* font; rdtkFont* font;
rdtkEngine* engine; rdtkEngine* engine;
rdtkNinePatch* ninePatch; rdtkNinePatch* ninePatch;

View File

@ -1,16 +1,22 @@
#include <stdio.h>
#include <stdint.h>
#include <rdtk/rdtk.h> #include <rdtk/rdtk.h>
#include <winpr/error.h>
int TestRdTkNinePatch(int argc, char* argv[]) int TestRdTkNinePatch(int argc, char* argv[])
{ {
rdtkEngine* engine = NULL; rdtkEngine* engine = NULL;
rdtkSurface* surface = NULL; rdtkSurface* surface = NULL;
DWORD scanline; uint32_t scanline;
DWORD width; uint32_t width;
DWORD height; uint32_t height;
BYTE* data = NULL; uint8_t* data = NULL;
int ret = -1; int ret = -1;
WINPR_UNUSED(argc);
WINPR_UNUSED(argv);
if (!(engine = rdtk_engine_new())) if (!(engine = rdtk_engine_new()))
{ {
printf("%s: error creating rdtk engine (%" PRIu32 ")\n", __FUNCTION__, GetLastError()); printf("%s: error creating rdtk engine (%" PRIu32 ")\n", __FUNCTION__, GetLastError());

View File

@ -20,7 +20,9 @@
#include "config.h" #include "config.h"
#endif #endif
#include <freerdp/log.h> #include <stdint.h>
#include <winpr/wlog.h>
#include <rdtk/rdtk.h> #include <rdtk/rdtk.h>
#include <X11/Xlib.h> #include <X11/Xlib.h>
@ -36,7 +38,7 @@ int main(int argc, char** argv)
int x, y; int x, y;
int width; int width;
int height; int height;
BYTE* buffer; uint8_t* buffer;
int scanline; int scanline;
int pf_count; int pf_count;
XEvent event; XEvent event;
@ -100,7 +102,7 @@ int main(int argc, char** argv)
return 1; return 1;
scanline = width * 4; scanline = width * 4;
buffer = (BYTE*)calloc(height, scanline); buffer = (uint8_t*)calloc(height, scanline);
if (!buffer) if (!buffer)
return 1; return 1;