2011-08-21 22:16:53 +04:00
|
|
|
/**
|
2012-10-09 07:02:04 +04:00
|
|
|
* FreeRDP: A Remote Desktop Protocol Implementation
|
2011-08-21 22:16:53 +04:00
|
|
|
* Glyph Cache
|
|
|
|
*
|
|
|
|
* Copyright 2011 Marc-Andre Moreau <marcandre.moreau@gmail.com>
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2022-02-16 13:20:38 +03:00
|
|
|
#include <freerdp/config.h>
|
2012-08-15 01:09:01 +04:00
|
|
|
|
2012-09-24 02:41:07 +04:00
|
|
|
#include <stdio.h>
|
|
|
|
|
2012-11-20 08:49:08 +04:00
|
|
|
#include <winpr/crt.h>
|
2021-09-06 15:00:12 +03:00
|
|
|
#include <winpr/assert.h>
|
2012-11-20 08:49:08 +04:00
|
|
|
|
2011-11-09 08:26:44 +04:00
|
|
|
#include <freerdp/freerdp.h>
|
2013-03-22 00:45:25 +04:00
|
|
|
#include <winpr/stream.h>
|
2011-08-21 22:16:53 +04:00
|
|
|
|
2014-09-12 16:36:29 +04:00
|
|
|
#include <freerdp/log.h>
|
2011-08-21 22:16:53 +04:00
|
|
|
|
2018-03-30 11:43:20 +03:00
|
|
|
#include "glyph.h"
|
2023-02-07 17:42:52 +03:00
|
|
|
#include "cache.h"
|
2018-03-30 11:43:20 +03:00
|
|
|
|
2014-09-12 16:36:29 +04:00
|
|
|
#define TAG FREERDP_TAG("cache.glyph")
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
static rdpGlyph* glyph_cache_get(rdpGlyphCache* glyph_cache, UINT32 id, UINT32 index);
|
|
|
|
static BOOL glyph_cache_put(rdpGlyphCache* glyph_cache, UINT32 id, UINT32 index, rdpGlyph* entry);
|
|
|
|
|
|
|
|
static const void* glyph_cache_fragment_get(rdpGlyphCache* glyph, UINT32 index, UINT32* count);
|
|
|
|
static BOOL glyph_cache_fragment_put(rdpGlyphCache* glyph, UINT32 index, UINT32 count,
|
|
|
|
const void* entry);
|
|
|
|
|
2020-04-25 09:33:45 +03:00
|
|
|
static UINT32 update_glyph_offset(const BYTE* data, size_t length, UINT32 index, INT32* x, INT32* y,
|
2019-11-06 17:24:51 +03:00
|
|
|
UINT32 ulCharInc, UINT32 flAccel)
|
2016-08-06 16:37:50 +03:00
|
|
|
{
|
|
|
|
if ((ulCharInc == 0) && (!(flAccel & SO_CHAR_INC_EQUAL_BM_BASE)))
|
|
|
|
{
|
|
|
|
UINT32 offset = data[index++];
|
|
|
|
|
|
|
|
if (offset & 0x80)
|
2016-08-16 15:30:18 +03:00
|
|
|
{
|
2020-04-25 09:33:45 +03:00
|
|
|
|
|
|
|
if (index + 1 < length)
|
|
|
|
{
|
|
|
|
offset = data[index++];
|
|
|
|
offset |= ((UINT32)data[index++]) << 8;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
WLog_WARN(TAG, "[%s] glyph index out of bound %" PRIu32 " [max %" PRIuz "]", index,
|
|
|
|
length);
|
2016-08-16 15:30:18 +03:00
|
|
|
}
|
2016-08-06 16:37:50 +03:00
|
|
|
|
|
|
|
if (flAccel & SO_VERTICAL)
|
|
|
|
*y += offset;
|
|
|
|
|
|
|
|
if (flAccel & SO_HORIZONTAL)
|
|
|
|
*x += offset;
|
|
|
|
}
|
|
|
|
|
|
|
|
return index;
|
|
|
|
}
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
static BOOL update_process_glyph(rdpContext* context, const BYTE* data, UINT32 cacheIndex, INT32* x,
|
|
|
|
INT32* y, UINT32 cacheId, UINT32 flAccel, BOOL fOpRedundant,
|
2016-10-04 10:57:52 +03:00
|
|
|
const RDP_RECT* bound)
|
2011-08-21 22:16:53 +04:00
|
|
|
{
|
2024-01-23 18:49:54 +03:00
|
|
|
INT32 sx = 0;
|
|
|
|
INT32 sy = 0;
|
2024-01-23 18:49:54 +03:00
|
|
|
INT32 dx = 0;
|
|
|
|
INT32 dy = 0;
|
|
|
|
rdpGlyph* glyph = NULL;
|
|
|
|
rdpGlyphCache* glyph_cache = NULL;
|
2016-07-18 18:45:30 +03:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
if (!context || !data || !x || !y || !context->graphics || !context->cache ||
|
|
|
|
!context->cache->glyph)
|
2016-07-18 18:45:30 +03:00
|
|
|
return FALSE;
|
|
|
|
|
2011-11-22 03:11:43 +04:00
|
|
|
glyph_cache = context->cache->glyph;
|
2011-11-09 21:16:09 +04:00
|
|
|
glyph = glyph_cache_get(glyph_cache, cacheId, cacheIndex);
|
2011-11-09 08:26:44 +04:00
|
|
|
|
2016-07-18 18:45:30 +03:00
|
|
|
if (!glyph)
|
|
|
|
return FALSE;
|
|
|
|
|
2016-08-17 10:26:59 +03:00
|
|
|
dx = glyph->x + *x;
|
|
|
|
dy = glyph->y + *y;
|
|
|
|
|
|
|
|
if (dx < bound->x)
|
2011-11-09 08:26:44 +04:00
|
|
|
{
|
2016-08-17 10:26:59 +03:00
|
|
|
sx = bound->x - dx;
|
|
|
|
dx = bound->x;
|
|
|
|
}
|
2011-11-09 21:16:09 +04:00
|
|
|
|
2016-08-17 10:26:59 +03:00
|
|
|
if (dy < bound->y)
|
|
|
|
{
|
|
|
|
sy = bound->y - dy;
|
|
|
|
dy = bound->y;
|
2011-11-09 08:26:44 +04:00
|
|
|
}
|
2016-07-18 18:45:30 +03:00
|
|
|
|
2016-08-17 10:26:59 +03:00
|
|
|
if ((dx <= (bound->x + bound->width)) && (dy <= (bound->y + bound->height)))
|
|
|
|
{
|
|
|
|
INT32 dw = glyph->cx - sx;
|
|
|
|
INT32 dh = glyph->cy - sy;
|
|
|
|
|
|
|
|
if ((dw + dx) > (bound->x + bound->width))
|
|
|
|
dw = (bound->x + bound->width) - (dw + dx);
|
|
|
|
|
|
|
|
if ((dh + dy) > (bound->y + bound->height))
|
|
|
|
dh = (bound->y + bound->height) - (dh + dy);
|
|
|
|
|
|
|
|
if ((dh > 0) && (dw > 0))
|
|
|
|
{
|
|
|
|
if (!glyph->Draw(context, glyph, dx, dy, dw, dh, sx, sy, fOpRedundant))
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (flAccel & SO_CHAR_INC_EQUAL_BM_BASE)
|
|
|
|
*x += glyph->cx;
|
|
|
|
|
2016-07-18 18:45:30 +03:00
|
|
|
return TRUE;
|
2011-11-09 08:26:44 +04:00
|
|
|
}
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
static BOOL update_process_glyph_fragments(rdpContext* context, const BYTE* data, UINT32 length,
|
|
|
|
UINT32 cacheId, UINT32 ulCharInc, UINT32 flAccel,
|
|
|
|
UINT32 bgcolor, UINT32 fgcolor, INT32 x, INT32 y,
|
|
|
|
INT32 bkX, INT32 bkY, INT32 bkWidth, INT32 bkHeight,
|
|
|
|
INT32 opX, INT32 opY, INT32 opWidth, INT32 opHeight,
|
|
|
|
BOOL fOpRedundant)
|
2011-11-09 08:26:44 +04:00
|
|
|
{
|
2024-01-23 18:49:54 +03:00
|
|
|
UINT32 id = 0;
|
|
|
|
UINT32 size = 0;
|
2016-04-05 18:07:45 +03:00
|
|
|
UINT32 index = 0;
|
2024-01-23 18:49:54 +03:00
|
|
|
const BYTE* fragments = NULL;
|
|
|
|
rdpGraphics* graphics = NULL;
|
|
|
|
rdpGlyphCache* glyph_cache = NULL;
|
|
|
|
rdpGlyph* glyph = NULL;
|
2016-08-17 10:26:59 +03:00
|
|
|
RDP_RECT bound;
|
2016-07-18 18:45:30 +03:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
if (!context || !data || !context->graphics || !context->cache || !context->cache->glyph)
|
2016-07-18 18:45:30 +03:00
|
|
|
return FALSE;
|
|
|
|
|
2011-11-22 03:11:43 +04:00
|
|
|
graphics = context->graphics;
|
|
|
|
glyph_cache = context->cache->glyph;
|
2016-07-18 15:30:26 +03:00
|
|
|
glyph = graphics->Glyph_Prototype;
|
2011-11-09 08:26:44 +04:00
|
|
|
|
2016-07-18 18:45:30 +03:00
|
|
|
if (!glyph)
|
|
|
|
return FALSE;
|
|
|
|
|
2019-10-28 14:45:22 +03:00
|
|
|
/* Limit op rectangle to visible screen. */
|
2016-08-17 10:26:59 +03:00
|
|
|
if (opX < 0)
|
|
|
|
{
|
|
|
|
opWidth += opX;
|
|
|
|
opX = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (opY < 0)
|
|
|
|
{
|
|
|
|
opHeight += opY;
|
|
|
|
opY = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (opWidth < 0)
|
|
|
|
opWidth = 0;
|
|
|
|
|
|
|
|
if (opHeight < 0)
|
|
|
|
opHeight = 0;
|
|
|
|
|
2019-10-28 14:45:22 +03:00
|
|
|
/* Limit bk rectangle to visible screen. */
|
2016-08-17 10:26:59 +03:00
|
|
|
if (bkX < 0)
|
|
|
|
{
|
|
|
|
bkWidth += bkX;
|
|
|
|
bkX = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (bkY < 0)
|
|
|
|
{
|
|
|
|
bkHeight += bkY;
|
|
|
|
bkY = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (bkWidth < 0)
|
|
|
|
bkWidth = 0;
|
|
|
|
|
|
|
|
if (bkHeight < 0)
|
|
|
|
bkHeight = 0;
|
|
|
|
|
2022-05-02 11:55:44 +03:00
|
|
|
if (opX + opWidth > (INT64)freerdp_settings_get_uint32(context->settings, FreeRDP_DesktopWidth))
|
2014-12-05 20:28:43 +03:00
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Some Microsoft servers send erroneous high values close to the
|
|
|
|
* sint16 maximum in the OpRight field of the GlyphIndex, FastIndex and
|
|
|
|
* FastGlyph drawing orders, probably a result of applications trying to
|
|
|
|
* clear the text line to the very right end.
|
|
|
|
* One example where this can be seen is typing in notepad.exe within
|
|
|
|
* a RDP session to Windows XP Professional SP3.
|
|
|
|
* This workaround prevents resulting problems in the UI callbacks.
|
|
|
|
*/
|
2022-05-02 11:55:44 +03:00
|
|
|
opWidth = freerdp_settings_get_uint32(context->settings, FreeRDP_DesktopWidth) - opX;
|
2014-12-05 20:28:43 +03:00
|
|
|
}
|
|
|
|
|
2022-05-02 11:55:44 +03:00
|
|
|
if (bkX + bkWidth > (INT64)freerdp_settings_get_uint32(context->settings, FreeRDP_DesktopWidth))
|
2016-08-17 10:26:59 +03:00
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Some Microsoft servers send erroneous high values close to the
|
|
|
|
* sint16 maximum in the OpRight field of the GlyphIndex, FastIndex and
|
|
|
|
* FastGlyph drawing orders, probably a result of applications trying to
|
|
|
|
* clear the text line to the very right end.
|
|
|
|
* One example where this can be seen is typing in notepad.exe within
|
|
|
|
* a RDP session to Windows XP Professional SP3.
|
|
|
|
* This workaround prevents resulting problems in the UI callbacks.
|
|
|
|
*/
|
2022-05-02 11:55:44 +03:00
|
|
|
bkWidth = freerdp_settings_get_uint32(context->settings, FreeRDP_DesktopWidth) - bkX;
|
2016-08-17 10:26:59 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
bound.x = bkX;
|
|
|
|
bound.y = bkY;
|
|
|
|
bound.width = bkWidth;
|
|
|
|
bound.height = bkHeight;
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
if (!glyph->BeginDraw(context, opX, opY, opWidth, opHeight, bgcolor, fgcolor, fOpRedundant))
|
2016-08-16 15:30:18 +03:00
|
|
|
return FALSE;
|
2011-11-09 08:26:44 +04:00
|
|
|
|
2018-11-19 15:58:53 +03:00
|
|
|
if (!IFCALLRESULT(TRUE, glyph->SetBounds, context, bkX, bkY, bkWidth, bkHeight))
|
|
|
|
return FALSE;
|
|
|
|
|
2016-07-18 18:45:30 +03:00
|
|
|
while (index < length)
|
2011-11-09 08:26:44 +04:00
|
|
|
{
|
2016-08-06 16:37:50 +03:00
|
|
|
const UINT32 op = data[index++];
|
|
|
|
|
|
|
|
switch (op)
|
2011-11-09 08:26:44 +04:00
|
|
|
{
|
|
|
|
case GLYPH_FRAGMENT_USE:
|
2020-04-25 09:33:45 +03:00
|
|
|
if (index + 1 >= length)
|
2016-08-17 10:26:59 +03:00
|
|
|
return FALSE;
|
2011-11-09 08:26:44 +04:00
|
|
|
|
2016-08-06 16:37:50 +03:00
|
|
|
id = data[index++];
|
2021-08-02 13:13:34 +03:00
|
|
|
fragments = (const BYTE*)glyph_cache_fragment_get(glyph_cache, id, &size);
|
2011-11-09 08:26:44 +04:00
|
|
|
|
2016-08-17 10:26:59 +03:00
|
|
|
if (fragments == NULL)
|
|
|
|
return FALSE;
|
|
|
|
|
2024-01-30 12:25:38 +03:00
|
|
|
for (size_t n = 0; n < size;)
|
2011-11-09 08:26:44 +04:00
|
|
|
{
|
2016-08-17 10:26:59 +03:00
|
|
|
const UINT32 fop = fragments[n++];
|
2020-04-25 09:33:45 +03:00
|
|
|
n = update_glyph_offset(fragments, size, n, &x, &y, ulCharInc, flAccel);
|
2016-08-17 10:26:59 +03:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
if (!update_process_glyph(context, fragments, fop, &x, &y, cacheId, flAccel,
|
|
|
|
fOpRedundant, &bound))
|
2016-08-17 10:26:59 +03:00
|
|
|
return FALSE;
|
2011-11-09 08:26:44 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GLYPH_FRAGMENT_ADD:
|
2016-08-06 16:37:50 +03:00
|
|
|
if (index + 2 > length)
|
2016-08-17 10:26:59 +03:00
|
|
|
return FALSE;
|
2011-11-09 08:26:44 +04:00
|
|
|
|
2016-08-06 16:37:50 +03:00
|
|
|
id = data[index++];
|
|
|
|
size = data[index++];
|
2016-08-17 10:26:59 +03:00
|
|
|
glyph_cache_fragment_put(glyph_cache, id, size, data);
|
2011-11-09 08:26:44 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2020-04-25 09:33:45 +03:00
|
|
|
index = update_glyph_offset(data, length, index, &x, &y, ulCharInc, flAccel);
|
2016-08-06 16:37:50 +03:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
if (!update_process_glyph(context, data, op, &x, &y, cacheId, flAccel, fOpRedundant,
|
|
|
|
&bound))
|
2016-08-06 16:37:50 +03:00
|
|
|
return FALSE;
|
|
|
|
|
2011-11-09 08:26:44 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-16 15:30:18 +03:00
|
|
|
return glyph->EndDraw(context, opX, opY, opWidth, opHeight, bgcolor, fgcolor);
|
2011-11-09 08:26:44 +04:00
|
|
|
}
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
static BOOL update_gdi_glyph_index(rdpContext* context, GLYPH_INDEX_ORDER* glyphIndex)
|
2011-11-09 08:26:44 +04:00
|
|
|
{
|
2024-01-23 18:49:54 +03:00
|
|
|
INT32 bkWidth = 0;
|
|
|
|
INT32 bkHeight = 0;
|
|
|
|
INT32 opWidth = 0;
|
|
|
|
INT32 opHeight = 0;
|
2016-07-18 18:45:30 +03:00
|
|
|
|
|
|
|
if (!context || !glyphIndex || !context->cache)
|
|
|
|
return FALSE;
|
|
|
|
|
2016-08-16 15:30:18 +03:00
|
|
|
if (glyphIndex->bkRight > glyphIndex->bkLeft)
|
|
|
|
bkWidth = glyphIndex->bkRight - glyphIndex->bkLeft + 1;
|
|
|
|
|
|
|
|
if (glyphIndex->opRight > glyphIndex->opLeft)
|
|
|
|
opWidth = glyphIndex->opRight - glyphIndex->opLeft + 1;
|
|
|
|
|
|
|
|
if (glyphIndex->bkBottom > glyphIndex->bkTop)
|
|
|
|
bkHeight = glyphIndex->bkBottom - glyphIndex->bkTop + 1;
|
|
|
|
|
|
|
|
if (glyphIndex->opBottom > glyphIndex->opTop)
|
|
|
|
opHeight = glyphIndex->opBottom - glyphIndex->opTop + 1;
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
return update_process_glyph_fragments(
|
|
|
|
context, glyphIndex->data, glyphIndex->cbData, glyphIndex->cacheId, glyphIndex->ulCharInc,
|
|
|
|
glyphIndex->flAccel, glyphIndex->backColor, glyphIndex->foreColor, glyphIndex->x,
|
|
|
|
glyphIndex->y, glyphIndex->bkLeft, glyphIndex->bkTop, bkWidth, bkHeight, glyphIndex->opLeft,
|
|
|
|
glyphIndex->opTop, opWidth, opHeight, glyphIndex->fOpRedundant);
|
2011-11-09 08:26:44 +04:00
|
|
|
}
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
static BOOL update_gdi_fast_index(rdpContext* context, const FAST_INDEX_ORDER* fastIndex)
|
2011-11-09 08:26:44 +04:00
|
|
|
{
|
2024-01-23 18:49:54 +03:00
|
|
|
INT32 x = 0;
|
|
|
|
INT32 y = 0;
|
|
|
|
INT32 opLeft = 0;
|
|
|
|
INT32 opTop = 0;
|
|
|
|
INT32 opRight = 0;
|
|
|
|
INT32 opBottom = 0;
|
2024-01-23 18:49:54 +03:00
|
|
|
INT32 opWidth = 0;
|
|
|
|
INT32 opHeight = 0;
|
|
|
|
INT32 bkWidth = 0;
|
|
|
|
INT32 bkHeight = 0;
|
2016-07-18 18:45:30 +03:00
|
|
|
|
|
|
|
if (!context || !fastIndex || !context->cache)
|
|
|
|
return FALSE;
|
|
|
|
|
2013-11-01 18:01:16 +04:00
|
|
|
opLeft = fastIndex->opLeft;
|
|
|
|
opTop = fastIndex->opTop;
|
|
|
|
opRight = fastIndex->opRight;
|
|
|
|
opBottom = fastIndex->opBottom;
|
|
|
|
x = fastIndex->x;
|
|
|
|
y = fastIndex->y;
|
2011-11-25 03:32:49 +04:00
|
|
|
|
|
|
|
if (opBottom == -32768)
|
|
|
|
{
|
2016-04-23 12:25:55 +03:00
|
|
|
BYTE flags = (BYTE)(opTop & 0x0F);
|
2011-11-25 03:32:49 +04:00
|
|
|
|
|
|
|
if (flags & 0x01)
|
2013-11-01 18:01:16 +04:00
|
|
|
opBottom = fastIndex->bkBottom;
|
2016-04-23 12:25:55 +03:00
|
|
|
|
2011-11-25 03:32:49 +04:00
|
|
|
if (flags & 0x02)
|
2013-11-01 18:01:16 +04:00
|
|
|
opRight = fastIndex->bkRight;
|
2016-04-23 12:25:55 +03:00
|
|
|
|
2011-11-25 03:32:49 +04:00
|
|
|
if (flags & 0x04)
|
2013-11-01 18:01:16 +04:00
|
|
|
opTop = fastIndex->bkTop;
|
2016-04-23 12:25:55 +03:00
|
|
|
|
2011-11-25 03:32:49 +04:00
|
|
|
if (flags & 0x08)
|
2013-11-01 18:01:16 +04:00
|
|
|
opLeft = fastIndex->bkLeft;
|
2011-11-25 03:32:49 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (opLeft == 0)
|
2013-11-01 18:01:16 +04:00
|
|
|
opLeft = fastIndex->bkLeft;
|
2011-11-25 03:32:49 +04:00
|
|
|
|
|
|
|
if (opRight == 0)
|
2013-11-01 18:01:16 +04:00
|
|
|
opRight = fastIndex->bkRight;
|
2011-11-25 03:32:49 +04:00
|
|
|
|
2015-10-14 23:16:19 +03:00
|
|
|
/* Server can send a massive number (32766) which appears to be
|
|
|
|
* undocumented special behavior for "Erase all the way right".
|
|
|
|
* X11 has nondeterministic results asking for a draw that wide. */
|
2022-05-02 11:55:44 +03:00
|
|
|
if (opRight > (INT64)freerdp_settings_get_uint32(context->settings, FreeRDP_DesktopWidth))
|
|
|
|
opRight = (int)freerdp_settings_get_uint32(context->settings, FreeRDP_DesktopWidth);
|
2015-10-14 23:16:19 +03:00
|
|
|
|
2011-11-25 03:32:49 +04:00
|
|
|
if (x == -32768)
|
2013-11-01 18:01:16 +04:00
|
|
|
x = fastIndex->bkLeft;
|
2011-11-25 03:32:49 +04:00
|
|
|
|
|
|
|
if (y == -32768)
|
2013-11-01 18:01:16 +04:00
|
|
|
y = fastIndex->bkTop;
|
2011-11-09 08:26:44 +04:00
|
|
|
|
2016-08-16 15:30:18 +03:00
|
|
|
if (fastIndex->bkRight > fastIndex->bkLeft)
|
|
|
|
bkWidth = fastIndex->bkRight - fastIndex->bkLeft + 1;
|
|
|
|
|
|
|
|
if (fastIndex->bkBottom > fastIndex->bkTop)
|
|
|
|
bkHeight = fastIndex->bkBottom - fastIndex->bkTop + 1;
|
|
|
|
|
|
|
|
if (opRight > opLeft)
|
|
|
|
opWidth = opRight - opLeft + 1;
|
|
|
|
|
|
|
|
if (opBottom > opTop)
|
|
|
|
opHeight = opBottom - opTop + 1;
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
return update_process_glyph_fragments(
|
|
|
|
context, fastIndex->data, fastIndex->cbData, fastIndex->cacheId, fastIndex->ulCharInc,
|
|
|
|
fastIndex->flAccel, fastIndex->backColor, fastIndex->foreColor, x, y, fastIndex->bkLeft,
|
|
|
|
fastIndex->bkTop, bkWidth, bkHeight, opLeft, opTop, opWidth, opHeight, FALSE);
|
2011-11-25 03:32:49 +04:00
|
|
|
}
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
static BOOL update_gdi_fast_glyph(rdpContext* context, const FAST_GLYPH_ORDER* fastGlyph)
|
2011-11-25 03:32:49 +04:00
|
|
|
{
|
2024-01-23 18:49:54 +03:00
|
|
|
INT32 x = 0;
|
|
|
|
INT32 y = 0;
|
2020-04-25 09:33:45 +03:00
|
|
|
BYTE text_data[4] = { 0 };
|
2024-01-23 18:49:54 +03:00
|
|
|
INT32 opLeft = 0;
|
|
|
|
INT32 opTop = 0;
|
|
|
|
INT32 opRight = 0;
|
|
|
|
INT32 opBottom = 0;
|
2024-01-23 18:49:54 +03:00
|
|
|
INT32 opWidth = 0;
|
|
|
|
INT32 opHeight = 0;
|
|
|
|
INT32 bkWidth = 0;
|
|
|
|
INT32 bkHeight = 0;
|
2024-01-23 18:49:54 +03:00
|
|
|
rdpCache* cache = NULL;
|
2016-07-18 18:45:30 +03:00
|
|
|
|
|
|
|
if (!context || !fastGlyph || !context->cache)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
cache = context->cache;
|
2013-11-01 18:01:16 +04:00
|
|
|
opLeft = fastGlyph->opLeft;
|
|
|
|
opTop = fastGlyph->opTop;
|
|
|
|
opRight = fastGlyph->opRight;
|
|
|
|
opBottom = fastGlyph->opBottom;
|
|
|
|
x = fastGlyph->x;
|
|
|
|
y = fastGlyph->y;
|
2011-11-25 03:32:49 +04:00
|
|
|
|
|
|
|
if (opBottom == -32768)
|
|
|
|
{
|
2016-04-23 12:25:55 +03:00
|
|
|
BYTE flags = (BYTE)(opTop & 0x0F);
|
2011-11-25 03:32:49 +04:00
|
|
|
|
|
|
|
if (flags & 0x01)
|
2013-11-01 18:01:16 +04:00
|
|
|
opBottom = fastGlyph->bkBottom;
|
2016-04-23 12:25:55 +03:00
|
|
|
|
2011-11-25 03:32:49 +04:00
|
|
|
if (flags & 0x02)
|
2013-11-01 18:01:16 +04:00
|
|
|
opRight = fastGlyph->bkRight;
|
2016-04-23 12:25:55 +03:00
|
|
|
|
2011-11-25 03:32:49 +04:00
|
|
|
if (flags & 0x04)
|
2013-11-01 18:01:16 +04:00
|
|
|
opTop = fastGlyph->bkTop;
|
2016-04-23 12:25:55 +03:00
|
|
|
|
2011-11-25 03:32:49 +04:00
|
|
|
if (flags & 0x08)
|
2013-11-01 18:01:16 +04:00
|
|
|
opLeft = fastGlyph->bkLeft;
|
2011-11-25 03:32:49 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (opLeft == 0)
|
2013-11-01 18:01:16 +04:00
|
|
|
opLeft = fastGlyph->bkLeft;
|
2011-11-25 03:32:49 +04:00
|
|
|
|
|
|
|
if (opRight == 0)
|
2013-11-01 18:01:16 +04:00
|
|
|
opRight = fastGlyph->bkRight;
|
2011-11-25 03:32:49 +04:00
|
|
|
|
2015-10-14 23:16:19 +03:00
|
|
|
/* See update_gdi_fast_index opRight comment. */
|
2022-05-02 11:55:44 +03:00
|
|
|
if (opRight > (INT64)freerdp_settings_get_uint32(context->settings, FreeRDP_DesktopWidth))
|
|
|
|
opRight = (int)freerdp_settings_get_uint32(context->settings, FreeRDP_DesktopWidth);
|
2015-10-14 23:16:19 +03:00
|
|
|
|
2011-11-25 03:32:49 +04:00
|
|
|
if (x == -32768)
|
2013-11-01 18:01:16 +04:00
|
|
|
x = fastGlyph->bkLeft;
|
2011-11-25 03:32:49 +04:00
|
|
|
|
|
|
|
if (y == -32768)
|
2013-11-01 18:01:16 +04:00
|
|
|
y = fastGlyph->bkTop;
|
2011-11-25 03:32:49 +04:00
|
|
|
|
2013-11-01 18:01:16 +04:00
|
|
|
if ((fastGlyph->cbData > 1) && (fastGlyph->glyphData.aj))
|
2011-11-25 03:32:49 +04:00
|
|
|
{
|
|
|
|
/* got option font that needs to go into cache */
|
2024-01-23 18:49:54 +03:00
|
|
|
rdpGlyph* glyph = NULL;
|
2016-07-18 18:45:30 +03:00
|
|
|
const GLYPH_DATA_V2* glyphData = &fastGlyph->glyphData;
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
glyph = Glyph_Alloc(context, glyphData->x, glyphData->y, glyphData->cx, glyphData->cy,
|
2016-10-04 10:57:52 +03:00
|
|
|
glyphData->cb, glyphData->aj);
|
2016-04-23 12:25:55 +03:00
|
|
|
|
2015-06-16 16:42:07 +03:00
|
|
|
if (!glyph)
|
|
|
|
return FALSE;
|
2016-04-23 12:25:55 +03:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
if (!glyph_cache_put(cache->glyph, fastGlyph->cacheId, fastGlyph->data[0], glyph))
|
2016-08-17 10:26:59 +03:00
|
|
|
{
|
|
|
|
glyph->Free(context, glyph);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2011-11-25 03:32:49 +04:00
|
|
|
}
|
|
|
|
|
2013-11-01 18:01:16 +04:00
|
|
|
text_data[0] = fastGlyph->data[0];
|
2011-11-25 03:32:49 +04:00
|
|
|
text_data[1] = 0;
|
2016-08-16 15:30:18 +03:00
|
|
|
|
|
|
|
if (fastGlyph->bkRight > fastGlyph->bkLeft)
|
|
|
|
bkWidth = fastGlyph->bkRight - fastGlyph->bkLeft + 1;
|
|
|
|
|
|
|
|
if (fastGlyph->bkBottom > fastGlyph->bkTop)
|
|
|
|
bkHeight = fastGlyph->bkBottom - fastGlyph->bkTop + 1;
|
|
|
|
|
|
|
|
if (opRight > opLeft)
|
|
|
|
opWidth = opRight - opLeft + 1;
|
|
|
|
|
|
|
|
if (opBottom > opTop)
|
|
|
|
opHeight = opBottom - opTop + 1;
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
return update_process_glyph_fragments(
|
2020-04-25 09:33:45 +03:00
|
|
|
context, text_data, sizeof(text_data), fastGlyph->cacheId, fastGlyph->ulCharInc,
|
|
|
|
fastGlyph->flAccel, fastGlyph->backColor, fastGlyph->foreColor, x, y, fastGlyph->bkLeft,
|
|
|
|
fastGlyph->bkTop, bkWidth, bkHeight, opLeft, opTop, opWidth, opHeight, FALSE);
|
2011-11-09 08:26:44 +04:00
|
|
|
}
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
static BOOL update_gdi_cache_glyph(rdpContext* context, const CACHE_GLYPH_ORDER* cacheGlyph)
|
2011-11-09 08:26:44 +04:00
|
|
|
{
|
2024-01-23 18:49:54 +03:00
|
|
|
rdpCache* cache = NULL;
|
2016-07-18 18:45:30 +03:00
|
|
|
|
|
|
|
if (!context || !cacheGlyph || !context->cache)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
cache = context->cache;
|
2011-11-09 08:26:44 +04:00
|
|
|
|
2024-01-30 12:25:38 +03:00
|
|
|
for (size_t i = 0; i < cacheGlyph->cGlyphs; i++)
|
2011-11-09 08:26:44 +04:00
|
|
|
{
|
2016-07-18 18:45:30 +03:00
|
|
|
const GLYPH_DATA* glyph_data = &cacheGlyph->glyphData[i];
|
2024-01-23 18:49:54 +03:00
|
|
|
rdpGlyph* glyph = NULL;
|
2016-04-23 12:25:55 +03:00
|
|
|
|
2016-07-18 18:45:30 +03:00
|
|
|
if (!glyph_data)
|
|
|
|
return FALSE;
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
if (!(glyph = Glyph_Alloc(context, glyph_data->x, glyph_data->y, glyph_data->cx,
|
|
|
|
glyph_data->cy, glyph_data->cb, glyph_data->aj)))
|
2015-04-14 11:14:23 +03:00
|
|
|
return FALSE;
|
2011-11-09 09:43:56 +04:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
if (!glyph_cache_put(cache->glyph, cacheGlyph->cacheId, glyph_data->cacheIndex, glyph))
|
2016-08-17 10:26:59 +03:00
|
|
|
{
|
|
|
|
glyph->Free(context, glyph);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2011-11-09 08:26:44 +04:00
|
|
|
}
|
2016-04-23 12:25:55 +03:00
|
|
|
|
2015-04-14 11:14:23 +03:00
|
|
|
return TRUE;
|
2011-11-09 08:26:44 +04:00
|
|
|
}
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
static BOOL update_gdi_cache_glyph_v2(rdpContext* context, const CACHE_GLYPH_V2_ORDER* cacheGlyphV2)
|
2011-11-09 08:26:44 +04:00
|
|
|
{
|
2024-01-23 18:49:54 +03:00
|
|
|
rdpCache* cache = NULL;
|
2016-07-18 18:45:30 +03:00
|
|
|
|
|
|
|
if (!context || !cacheGlyphV2 || !context->cache)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
cache = context->cache;
|
2011-11-09 08:26:44 +04:00
|
|
|
|
2024-01-30 12:25:38 +03:00
|
|
|
for (size_t i = 0; i < cacheGlyphV2->cGlyphs; i++)
|
2012-01-05 05:20:58 +04:00
|
|
|
{
|
2016-07-18 12:16:36 +03:00
|
|
|
const GLYPH_DATA_V2* glyphData = &cacheGlyphV2->glyphData[i];
|
2024-01-23 18:49:54 +03:00
|
|
|
rdpGlyph* glyph = NULL;
|
2016-07-18 18:45:30 +03:00
|
|
|
|
|
|
|
if (!glyphData)
|
|
|
|
return FALSE;
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
glyph = Glyph_Alloc(context, glyphData->x, glyphData->y, glyphData->cx, glyphData->cy,
|
|
|
|
glyphData->cb, glyphData->aj);
|
2016-04-23 12:25:55 +03:00
|
|
|
|
2015-04-14 11:14:23 +03:00
|
|
|
if (!glyph)
|
|
|
|
return FALSE;
|
2012-01-05 05:20:58 +04:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
if (!glyph_cache_put(cache->glyph, cacheGlyphV2->cacheId, glyphData->cacheIndex, glyph))
|
2016-08-17 10:26:59 +03:00
|
|
|
{
|
|
|
|
glyph->Free(context, glyph);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2012-01-05 05:20:58 +04:00
|
|
|
}
|
2016-04-23 12:25:55 +03:00
|
|
|
|
2015-04-14 11:14:23 +03:00
|
|
|
return TRUE;
|
2011-11-09 08:26:44 +04:00
|
|
|
}
|
|
|
|
|
2013-11-01 18:01:16 +04:00
|
|
|
rdpGlyph* glyph_cache_get(rdpGlyphCache* glyphCache, UINT32 id, UINT32 index)
|
2011-11-09 08:26:44 +04:00
|
|
|
{
|
2024-01-23 18:49:54 +03:00
|
|
|
rdpGlyph* glyph = NULL;
|
2021-09-06 15:00:12 +03:00
|
|
|
|
|
|
|
WINPR_ASSERT(glyphCache);
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
WLog_Print(glyphCache->log, WLOG_DEBUG, "GlyphCacheGet: id: %" PRIu32 " index: %" PRIu32 "", id,
|
2016-10-04 10:57:52 +03:00
|
|
|
index);
|
2013-11-01 18:01:16 +04:00
|
|
|
|
2011-08-21 22:16:53 +04:00
|
|
|
if (id > 9)
|
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
WLog_ERR(TAG, "invalid glyph cache id: %" PRIu32 "", id);
|
2011-08-21 22:16:53 +04:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2021-09-06 15:00:12 +03:00
|
|
|
WINPR_ASSERT(glyphCache->glyphCache);
|
2013-11-01 18:01:16 +04:00
|
|
|
if (index > glyphCache->glyphCache[id].number)
|
2011-08-21 22:16:53 +04:00
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
WLog_ERR(TAG, "index %" PRIu32 " out of range for cache id: %" PRIu32 "", index, id);
|
2011-08-21 22:16:53 +04:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2013-11-01 18:01:16 +04:00
|
|
|
glyph = glyphCache->glyphCache[id].entries[index];
|
2011-11-09 21:57:31 +04:00
|
|
|
|
2013-11-01 18:01:16 +04:00
|
|
|
if (!glyph)
|
2019-11-06 17:24:51 +03:00
|
|
|
WLog_ERR(TAG, "no glyph found at cache index: %" PRIu32 " in cache id: %" PRIu32 "", index,
|
|
|
|
id);
|
2011-08-21 22:54:08 +04:00
|
|
|
|
2011-11-09 21:57:31 +04:00
|
|
|
return glyph;
|
2011-08-21 22:16:53 +04:00
|
|
|
}
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
BOOL glyph_cache_put(rdpGlyphCache* glyphCache, UINT32 id, UINT32 index, rdpGlyph* glyph)
|
2011-08-21 22:16:53 +04:00
|
|
|
{
|
2024-01-23 18:49:54 +03:00
|
|
|
rdpGlyph* prevGlyph = NULL;
|
2011-11-09 09:43:56 +04:00
|
|
|
|
2021-09-06 15:00:12 +03:00
|
|
|
WINPR_ASSERT(glyphCache);
|
|
|
|
|
2011-08-21 22:16:53 +04:00
|
|
|
if (id > 9)
|
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
WLog_ERR(TAG, "invalid glyph cache id: %" PRIu32 "", id);
|
2016-07-18 12:16:36 +03:00
|
|
|
return FALSE;
|
2011-08-21 22:16:53 +04:00
|
|
|
}
|
|
|
|
|
2021-09-06 15:00:12 +03:00
|
|
|
WINPR_ASSERT(glyphCache->glyphCache);
|
2020-05-25 10:42:02 +03:00
|
|
|
if (index >= glyphCache->glyphCache[id].number)
|
2011-08-21 22:16:53 +04:00
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
WLog_ERR(TAG, "invalid glyph cache index: %" PRIu32 " in cache id: %" PRIu32 "", index, id);
|
2016-07-18 12:16:36 +03:00
|
|
|
return FALSE;
|
2011-08-21 22:16:53 +04:00
|
|
|
}
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
WLog_Print(glyphCache->log, WLOG_DEBUG, "GlyphCachePut: id: %" PRIu32 " index: %" PRIu32 "", id,
|
2016-10-04 10:57:52 +03:00
|
|
|
index);
|
2013-11-01 18:01:16 +04:00
|
|
|
prevGlyph = glyphCache->glyphCache[id].entries[index];
|
|
|
|
|
|
|
|
if (prevGlyph)
|
2021-09-06 15:00:12 +03:00
|
|
|
{
|
|
|
|
WINPR_ASSERT(prevGlyph->Free);
|
2016-07-20 11:06:45 +03:00
|
|
|
prevGlyph->Free(glyphCache->context, prevGlyph);
|
2021-09-06 15:00:12 +03:00
|
|
|
}
|
2011-11-09 09:43:56 +04:00
|
|
|
|
2013-11-01 18:01:16 +04:00
|
|
|
glyphCache->glyphCache[id].entries[index] = glyph;
|
2016-07-18 12:16:36 +03:00
|
|
|
return TRUE;
|
2011-08-21 22:16:53 +04:00
|
|
|
}
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
const void* glyph_cache_fragment_get(rdpGlyphCache* glyphCache, UINT32 index, UINT32* size)
|
2011-09-19 02:29:23 +04:00
|
|
|
{
|
2024-01-23 18:49:54 +03:00
|
|
|
void* fragment = NULL;
|
2011-09-19 02:29:23 +04:00
|
|
|
|
2021-09-06 15:00:12 +03:00
|
|
|
WINPR_ASSERT(glyphCache);
|
|
|
|
WINPR_ASSERT(glyphCache->fragCache.entries);
|
|
|
|
|
2013-11-01 18:01:16 +04:00
|
|
|
if (index > 255)
|
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
WLog_ERR(TAG, "invalid glyph cache fragment index: %" PRIu32 "", index);
|
2013-11-01 18:01:16 +04:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
fragment = glyphCache->fragCache.entries[index].fragment;
|
2019-11-06 17:24:51 +03:00
|
|
|
*size = (BYTE)glyphCache->fragCache.entries[index].size;
|
2016-07-18 18:45:30 +03:00
|
|
|
WLog_Print(glyphCache->log, WLOG_DEBUG,
|
2019-11-06 17:24:51 +03:00
|
|
|
"GlyphCacheFragmentGet: index: %" PRIu32 " size: %" PRIu32 "", index, *size);
|
2011-09-19 02:29:23 +04:00
|
|
|
|
2013-11-01 18:01:16 +04:00
|
|
|
if (!fragment)
|
2019-11-06 17:24:51 +03:00
|
|
|
WLog_ERR(TAG, "invalid glyph fragment at index:%" PRIu32 "", index);
|
2011-11-09 21:57:31 +04:00
|
|
|
|
2011-11-09 21:16:09 +04:00
|
|
|
return fragment;
|
2011-09-19 02:29:23 +04:00
|
|
|
}
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
BOOL glyph_cache_fragment_put(rdpGlyphCache* glyphCache, UINT32 index, UINT32 size,
|
|
|
|
const void* fragment)
|
2011-11-09 08:26:44 +04:00
|
|
|
{
|
2024-01-23 18:49:54 +03:00
|
|
|
void* prevFragment = NULL;
|
|
|
|
void* copy = NULL;
|
2011-11-09 21:57:31 +04:00
|
|
|
|
2021-09-06 15:00:12 +03:00
|
|
|
WINPR_ASSERT(glyphCache);
|
|
|
|
WINPR_ASSERT(glyphCache->fragCache.entries);
|
|
|
|
|
2013-11-01 18:01:16 +04:00
|
|
|
if (index > 255)
|
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
WLog_ERR(TAG, "invalid glyph cache fragment index: %" PRIu32 "", index);
|
2016-08-17 10:26:59 +03:00
|
|
|
return FALSE;
|
2013-11-01 18:01:16 +04:00
|
|
|
}
|
|
|
|
|
2016-08-17 10:26:59 +03:00
|
|
|
copy = malloc(size);
|
|
|
|
|
|
|
|
if (!copy)
|
|
|
|
return FALSE;
|
|
|
|
|
2016-07-18 18:45:30 +03:00
|
|
|
WLog_Print(glyphCache->log, WLOG_DEBUG,
|
2019-11-06 17:24:51 +03:00
|
|
|
"GlyphCacheFragmentPut: index: %" PRIu32 " size: %" PRIu32 "", index, size);
|
2016-08-17 10:26:59 +03:00
|
|
|
CopyMemory(copy, fragment, size);
|
2013-11-01 18:01:16 +04:00
|
|
|
prevFragment = glyphCache->fragCache.entries[index].fragment;
|
2016-08-17 10:26:59 +03:00
|
|
|
glyphCache->fragCache.entries[index].fragment = copy;
|
2013-11-01 18:01:16 +04:00
|
|
|
glyphCache->fragCache.entries[index].size = size;
|
2015-05-11 10:07:39 +03:00
|
|
|
free(prevFragment);
|
2016-08-17 10:26:59 +03:00
|
|
|
return TRUE;
|
2011-11-09 08:26:44 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void glyph_cache_register_callbacks(rdpUpdate* update)
|
2011-09-19 02:29:23 +04:00
|
|
|
{
|
2021-09-10 10:06:35 +03:00
|
|
|
WINPR_ASSERT(update);
|
|
|
|
WINPR_ASSERT(update->context);
|
|
|
|
WINPR_ASSERT(update->primary);
|
|
|
|
WINPR_ASSERT(update->secondary);
|
|
|
|
|
2021-09-17 09:59:10 +03:00
|
|
|
if (!freerdp_settings_get_bool(update->context->settings, FreeRDP_DeactivateClientDecoding))
|
|
|
|
{
|
|
|
|
update->primary->GlyphIndex = update_gdi_glyph_index;
|
|
|
|
update->primary->FastIndex = update_gdi_fast_index;
|
|
|
|
update->primary->FastGlyph = update_gdi_fast_glyph;
|
|
|
|
update->secondary->CacheGlyph = update_gdi_cache_glyph;
|
|
|
|
update->secondary->CacheGlyphV2 = update_gdi_cache_glyph_v2;
|
|
|
|
}
|
2011-09-19 02:29:23 +04:00
|
|
|
}
|
|
|
|
|
2021-09-06 15:00:12 +03:00
|
|
|
rdpGlyphCache* glyph_cache_new(rdpContext* context)
|
2011-08-21 22:16:53 +04:00
|
|
|
{
|
2024-01-23 18:49:54 +03:00
|
|
|
rdpGlyphCache* glyphCache = NULL;
|
|
|
|
rdpSettings* settings = NULL;
|
2021-09-06 15:00:12 +03:00
|
|
|
|
|
|
|
WINPR_ASSERT(context);
|
|
|
|
|
|
|
|
settings = context->settings;
|
|
|
|
WINPR_ASSERT(settings);
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
glyphCache = (rdpGlyphCache*)calloc(1, sizeof(rdpGlyphCache));
|
2011-08-21 22:16:53 +04:00
|
|
|
|
2016-10-04 10:57:52 +03:00
|
|
|
if (!glyphCache)
|
|
|
|
return NULL;
|
2011-08-21 22:16:53 +04:00
|
|
|
|
2016-10-04 10:57:52 +03:00
|
|
|
glyphCache->log = WLog_Get("com.freerdp.cache.glyph");
|
2021-09-06 15:00:12 +03:00
|
|
|
glyphCache->context = context;
|
2011-08-21 22:16:53 +04:00
|
|
|
|
2024-01-30 12:25:38 +03:00
|
|
|
for (size_t i = 0; i < 10; i++)
|
2016-10-04 10:57:52 +03:00
|
|
|
{
|
2022-05-02 11:55:44 +03:00
|
|
|
const GLYPH_CACHE_DEFINITION* currentGlyph =
|
|
|
|
freerdp_settings_get_pointer_array(settings, FreeRDP_GlyphCache, i);
|
|
|
|
GLYPH_CACHE* currentCache = &glyphCache->glyphCache[i];
|
|
|
|
currentCache->number = currentGlyph->cacheEntries;
|
|
|
|
currentCache->maxCellSize = currentGlyph->cacheMaximumCellSize;
|
|
|
|
currentCache->entries = (rdpGlyph**)calloc(currentCache->number, sizeof(rdpGlyph*));
|
|
|
|
|
|
|
|
if (!currentCache->entries)
|
2016-10-04 10:57:52 +03:00
|
|
|
goto fail;
|
2011-08-21 22:16:53 +04:00
|
|
|
}
|
|
|
|
|
2013-11-01 18:01:16 +04:00
|
|
|
return glyphCache;
|
2016-10-04 10:57:52 +03:00
|
|
|
fail:
|
2024-02-04 13:11:29 +03:00
|
|
|
WINPR_PRAGMA_DIAG_PUSH
|
|
|
|
WINPR_PRAGMA_DIAG_IGNORED_MISMATCHED_DEALLOC
|
2016-10-04 10:57:52 +03:00
|
|
|
glyph_cache_free(glyphCache);
|
2024-02-04 13:11:29 +03:00
|
|
|
WINPR_PRAGMA_DIAG_POP
|
2016-10-04 10:57:52 +03:00
|
|
|
return NULL;
|
2011-08-21 22:16:53 +04:00
|
|
|
}
|
|
|
|
|
2013-11-01 18:01:16 +04:00
|
|
|
void glyph_cache_free(rdpGlyphCache* glyphCache)
|
2011-08-21 22:16:53 +04:00
|
|
|
{
|
2013-11-01 18:01:16 +04:00
|
|
|
if (glyphCache)
|
2011-08-21 22:16:53 +04:00
|
|
|
{
|
2016-10-19 12:06:25 +03:00
|
|
|
GLYPH_CACHE* cache = glyphCache->glyphCache;
|
2011-08-21 22:16:53 +04:00
|
|
|
|
2024-01-30 12:25:38 +03:00
|
|
|
for (size_t i = 0; i < 10; i++)
|
2011-08-21 22:16:53 +04:00
|
|
|
{
|
2019-10-16 19:49:24 +03:00
|
|
|
rdpGlyph** entries = cache[i].entries;
|
2016-10-19 12:06:25 +03:00
|
|
|
|
2019-10-16 19:49:24 +03:00
|
|
|
if (!entries)
|
|
|
|
continue;
|
2012-02-02 03:42:20 +04:00
|
|
|
|
2024-01-30 12:25:38 +03:00
|
|
|
for (size_t j = 0; j < cache[i].number; j++)
|
2019-10-16 19:49:24 +03:00
|
|
|
{
|
|
|
|
rdpGlyph* glyph = entries[j];
|
2016-10-19 12:06:25 +03:00
|
|
|
|
2019-10-16 19:49:24 +03:00
|
|
|
if (glyph)
|
|
|
|
{
|
|
|
|
glyph->Free(glyphCache->context, glyph);
|
|
|
|
entries[j] = NULL;
|
2012-01-16 00:35:08 +04:00
|
|
|
}
|
2016-10-19 12:06:25 +03:00
|
|
|
}
|
2019-10-16 19:49:24 +03:00
|
|
|
|
|
|
|
free(entries);
|
|
|
|
cache[i].entries = NULL;
|
2011-08-21 22:16:53 +04:00
|
|
|
}
|
|
|
|
|
2024-01-30 12:25:38 +03:00
|
|
|
for (size_t i = 0; i < ARRAYSIZE(glyphCache->fragCache.entries); i++)
|
2012-01-16 00:35:08 +04:00
|
|
|
{
|
2022-09-30 12:09:05 +03:00
|
|
|
free(glyphCache->fragCache.entries[i].fragment);
|
|
|
|
glyphCache->fragCache.entries[i].fragment = NULL;
|
2012-01-16 00:35:08 +04:00
|
|
|
}
|
2011-08-21 22:16:53 +04:00
|
|
|
|
2013-11-01 18:01:16 +04:00
|
|
|
free(glyphCache);
|
2011-08-21 22:16:53 +04:00
|
|
|
}
|
|
|
|
}
|
2018-03-30 11:43:20 +03:00
|
|
|
|
|
|
|
CACHE_GLYPH_ORDER* copy_cache_glyph_order(rdpContext* context, const CACHE_GLYPH_ORDER* glyph)
|
|
|
|
{
|
2024-01-23 18:49:54 +03:00
|
|
|
CACHE_GLYPH_ORDER* dst = NULL;
|
2021-09-06 15:00:12 +03:00
|
|
|
|
|
|
|
WINPR_ASSERT(context);
|
|
|
|
|
|
|
|
dst = calloc(1, sizeof(CACHE_GLYPH_ORDER));
|
2018-03-30 11:43:20 +03:00
|
|
|
|
|
|
|
if (!dst || !glyph)
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
*dst = *glyph;
|
|
|
|
|
2024-01-30 12:25:38 +03:00
|
|
|
for (size_t x = 0; x < glyph->cGlyphs; x++)
|
2018-03-30 11:43:20 +03:00
|
|
|
{
|
|
|
|
const GLYPH_DATA* src = &glyph->glyphData[x];
|
|
|
|
GLYPH_DATA* data = &dst->glyphData[x];
|
|
|
|
|
|
|
|
if (src->aj)
|
|
|
|
{
|
|
|
|
const size_t size = src->cb;
|
|
|
|
data->aj = malloc(size);
|
|
|
|
|
|
|
|
if (!data->aj)
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
memcpy(data->aj, src->aj, size);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (glyph->unicodeCharacters)
|
|
|
|
{
|
2018-11-29 13:07:46 +03:00
|
|
|
if (glyph->cGlyphs == 0)
|
|
|
|
goto fail;
|
|
|
|
|
2018-03-30 11:43:20 +03:00
|
|
|
dst->unicodeCharacters = calloc(glyph->cGlyphs, sizeof(WCHAR));
|
|
|
|
|
|
|
|
if (!dst->unicodeCharacters)
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
memcpy(dst->unicodeCharacters, glyph->unicodeCharacters, sizeof(WCHAR) * glyph->cGlyphs);
|
|
|
|
}
|
|
|
|
|
|
|
|
return dst;
|
|
|
|
fail:
|
|
|
|
free_cache_glyph_order(context, dst);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
void free_cache_glyph_order(rdpContext* context, CACHE_GLYPH_ORDER* glyph)
|
|
|
|
{
|
|
|
|
if (glyph)
|
|
|
|
{
|
2024-01-30 12:25:38 +03:00
|
|
|
for (size_t x = 0; x < ARRAYSIZE(glyph->glyphData); x++)
|
2018-03-30 11:43:20 +03:00
|
|
|
free(glyph->glyphData[x].aj);
|
|
|
|
|
|
|
|
free(glyph->unicodeCharacters);
|
|
|
|
}
|
|
|
|
|
|
|
|
free(glyph);
|
|
|
|
}
|
|
|
|
|
|
|
|
CACHE_GLYPH_V2_ORDER* copy_cache_glyph_v2_order(rdpContext* context,
|
2019-11-06 17:24:51 +03:00
|
|
|
const CACHE_GLYPH_V2_ORDER* glyph)
|
2018-03-30 11:43:20 +03:00
|
|
|
{
|
2024-01-23 18:49:54 +03:00
|
|
|
CACHE_GLYPH_V2_ORDER* dst = NULL;
|
2021-09-06 15:00:12 +03:00
|
|
|
|
|
|
|
WINPR_ASSERT(context);
|
|
|
|
|
|
|
|
dst = calloc(1, sizeof(CACHE_GLYPH_V2_ORDER));
|
2018-03-30 11:43:20 +03:00
|
|
|
|
|
|
|
if (!dst || !glyph)
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
*dst = *glyph;
|
|
|
|
|
2024-01-30 12:25:38 +03:00
|
|
|
for (size_t x = 0; x < glyph->cGlyphs; x++)
|
2018-03-30 11:43:20 +03:00
|
|
|
{
|
|
|
|
const GLYPH_DATA_V2* src = &glyph->glyphData[x];
|
|
|
|
GLYPH_DATA_V2* data = &dst->glyphData[x];
|
|
|
|
|
|
|
|
if (src->aj)
|
|
|
|
{
|
|
|
|
const size_t size = src->cb;
|
|
|
|
data->aj = malloc(size);
|
|
|
|
|
|
|
|
if (!data->aj)
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
memcpy(data->aj, src->aj, size);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (glyph->unicodeCharacters)
|
|
|
|
{
|
2018-11-29 13:07:46 +03:00
|
|
|
if (glyph->cGlyphs == 0)
|
|
|
|
goto fail;
|
|
|
|
|
2018-03-30 11:43:20 +03:00
|
|
|
dst->unicodeCharacters = calloc(glyph->cGlyphs, sizeof(WCHAR));
|
|
|
|
|
|
|
|
if (!dst->unicodeCharacters)
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
memcpy(dst->unicodeCharacters, glyph->unicodeCharacters, sizeof(WCHAR) * glyph->cGlyphs);
|
|
|
|
}
|
|
|
|
|
|
|
|
return dst;
|
|
|
|
fail:
|
|
|
|
free_cache_glyph_v2_order(context, dst);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
void free_cache_glyph_v2_order(rdpContext* context, CACHE_GLYPH_V2_ORDER* glyph)
|
|
|
|
{
|
|
|
|
if (glyph)
|
|
|
|
{
|
2024-01-30 12:25:38 +03:00
|
|
|
for (size_t x = 0; x < ARRAYSIZE(glyph->glyphData); x++)
|
2018-03-30 11:43:20 +03:00
|
|
|
free(glyph->glyphData[x].aj);
|
|
|
|
|
|
|
|
free(glyph->unicodeCharacters);
|
|
|
|
}
|
|
|
|
|
|
|
|
free(glyph);
|
|
|
|
}
|