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.
|
|
|
|
*/
|
|
|
|
|
2012-08-15 01:09:01 +04:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
2012-09-24 02:41:07 +04:00
|
|
|
#include <stdio.h>
|
|
|
|
|
2012-11-20 08:49:08 +04:00
|
|
|
#include <winpr/crt.h>
|
|
|
|
|
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
|
|
|
|
|
|
|
#include <freerdp/cache/glyph.h>
|
|
|
|
|
2012-10-09 11:01:37 +04:00
|
|
|
void update_process_glyph(rdpContext* context, BYTE* data, int* index,
|
2012-10-09 11:26:39 +04:00
|
|
|
int* x, int* y, UINT32 cacheId, UINT32 ulCharInc, UINT32 flAccel)
|
2011-08-21 22:16:53 +04:00
|
|
|
{
|
2011-11-09 08:26:44 +04:00
|
|
|
int offset;
|
|
|
|
rdpGlyph* glyph;
|
2012-10-09 11:26:39 +04:00
|
|
|
UINT32 cacheIndex;
|
2011-11-09 09:43:56 +04:00
|
|
|
rdpGraphics* graphics;
|
2011-11-09 08:26:44 +04:00
|
|
|
rdpGlyphCache* glyph_cache;
|
|
|
|
|
2011-11-22 03:11:43 +04:00
|
|
|
graphics = context->graphics;
|
|
|
|
glyph_cache = context->cache->glyph;
|
2011-11-09 08:26:44 +04:00
|
|
|
|
2011-11-28 02:06:34 +04:00
|
|
|
cacheIndex = data[*index];
|
2011-11-09 08:26:44 +04:00
|
|
|
|
2011-11-09 21:16:09 +04:00
|
|
|
glyph = glyph_cache_get(glyph_cache, cacheId, cacheIndex);
|
2011-11-09 08:26:44 +04:00
|
|
|
|
2011-11-09 21:16:09 +04:00
|
|
|
if ((ulCharInc == 0) && (!(flAccel & SO_CHAR_INC_EQUAL_BM_BASE)))
|
2011-11-09 08:26:44 +04:00
|
|
|
{
|
2011-11-28 02:06:34 +04:00
|
|
|
(*index)++;
|
2011-11-09 21:16:09 +04:00
|
|
|
offset = data[*index];
|
2011-11-09 08:26:44 +04:00
|
|
|
|
2011-11-09 21:16:09 +04:00
|
|
|
if (offset & 0x80)
|
|
|
|
{
|
|
|
|
offset = data[*index + 1] | (data[*index + 2] << 8);
|
|
|
|
(*index)++;
|
|
|
|
(*index)++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (flAccel & SO_VERTICAL)
|
2011-11-09 08:26:44 +04:00
|
|
|
*y += offset;
|
|
|
|
else
|
|
|
|
*x += offset;
|
|
|
|
}
|
2011-11-09 21:16:09 +04:00
|
|
|
|
|
|
|
if (glyph != NULL)
|
2011-11-09 08:26:44 +04:00
|
|
|
{
|
2011-11-22 03:11:43 +04:00
|
|
|
Glyph_Draw(context, glyph, glyph->x + *x, glyph->y + *y);
|
2011-11-09 21:16:09 +04:00
|
|
|
|
|
|
|
if (flAccel & SO_CHAR_INC_EQUAL_BM_BASE)
|
|
|
|
*x += glyph->cx;
|
2011-11-09 08:26:44 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-10-09 11:26:39 +04:00
|
|
|
void update_process_glyph_fragments(rdpContext* context, BYTE* data, UINT32 length,
|
|
|
|
UINT32 cacheId, UINT32 ulCharInc, UINT32 flAccel, UINT32 bgcolor, UINT32 fgcolor, int x, int y,
|
2011-11-09 08:26:44 +04:00
|
|
|
int bkX, int bkY, int bkWidth, int bkHeight, int opX, int opY, int opWidth, int opHeight)
|
|
|
|
{
|
|
|
|
int n;
|
2012-10-09 11:26:39 +04:00
|
|
|
UINT32 id;
|
|
|
|
UINT32 size;
|
2011-11-09 08:26:44 +04:00
|
|
|
int index = 0;
|
2012-10-09 11:01:37 +04:00
|
|
|
BYTE* fragments;
|
2011-11-09 09:43:56 +04:00
|
|
|
rdpGraphics* graphics;
|
2011-11-09 08:26:44 +04:00
|
|
|
rdpGlyphCache* glyph_cache;
|
|
|
|
|
2011-11-22 03:11:43 +04:00
|
|
|
graphics = context->graphics;
|
|
|
|
glyph_cache = context->cache->glyph;
|
2011-11-09 08:26:44 +04:00
|
|
|
|
2012-01-09 04:08:13 +04:00
|
|
|
if (opWidth > 0 && opHeight > 0)
|
2011-11-22 03:11:43 +04:00
|
|
|
Glyph_BeginDraw(context, opX, opY, opWidth, opHeight, bgcolor, fgcolor);
|
2011-11-09 21:57:31 +04:00
|
|
|
else
|
2011-11-22 03:11:43 +04:00
|
|
|
Glyph_BeginDraw(context, 0, 0, 0, 0, bgcolor, fgcolor);
|
2011-11-09 08:26:44 +04:00
|
|
|
|
2011-12-04 02:24:18 +04:00
|
|
|
while (index < (int) length)
|
2011-11-09 08:26:44 +04:00
|
|
|
{
|
|
|
|
switch (data[index])
|
|
|
|
{
|
|
|
|
case GLYPH_FRAGMENT_USE:
|
|
|
|
|
2011-12-04 02:24:18 +04:00
|
|
|
if (index + 2 > (int) length)
|
2011-11-09 08:26:44 +04:00
|
|
|
{
|
2011-11-09 21:16:09 +04:00
|
|
|
/* at least one byte need to follow */
|
2011-11-09 08:26:44 +04:00
|
|
|
index = length = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
id = data[index + 1];
|
2012-10-09 11:01:37 +04:00
|
|
|
fragments = (BYTE*) glyph_cache_fragment_get(glyph_cache, id, &size);
|
2011-11-09 08:26:44 +04:00
|
|
|
|
2011-11-09 21:16:09 +04:00
|
|
|
if (fragments != NULL)
|
2011-11-09 08:26:44 +04:00
|
|
|
{
|
2011-11-09 21:16:09 +04:00
|
|
|
if ((ulCharInc == 0) && (!(flAccel & SO_CHAR_INC_EQUAL_BM_BASE)))
|
|
|
|
{
|
|
|
|
if (flAccel & SO_VERTICAL)
|
|
|
|
y += data[index + 2];
|
|
|
|
else
|
|
|
|
x += data[index + 2];
|
|
|
|
}
|
|
|
|
|
2011-12-04 02:24:18 +04:00
|
|
|
for (n = 0; n < (int) size; n++)
|
2011-11-09 21:16:09 +04:00
|
|
|
{
|
2011-11-22 03:11:43 +04:00
|
|
|
update_process_glyph(context, fragments, &n, &x, &y, cacheId, ulCharInc, flAccel);
|
2011-11-09 21:16:09 +04:00
|
|
|
}
|
2011-11-09 08:26:44 +04:00
|
|
|
}
|
|
|
|
|
2011-12-04 02:24:18 +04:00
|
|
|
index += (index + 2 < (int) length) ? 3 : 2;
|
2011-11-09 08:26:44 +04:00
|
|
|
length -= index;
|
|
|
|
data = &(data[index]);
|
|
|
|
index = 0;
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GLYPH_FRAGMENT_ADD:
|
|
|
|
|
2011-12-04 02:24:18 +04:00
|
|
|
if (index + 3 > (int) length)
|
2011-11-09 08:26:44 +04:00
|
|
|
{
|
2011-11-09 21:16:09 +04:00
|
|
|
/* at least two bytes need to follow */
|
2011-11-09 08:26:44 +04:00
|
|
|
index = length = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
id = data[index + 1];
|
|
|
|
size = data[index + 2];
|
2011-11-09 21:16:09 +04:00
|
|
|
|
2012-10-09 11:01:37 +04:00
|
|
|
fragments = (BYTE*) malloc(size);
|
2011-11-09 21:16:09 +04:00
|
|
|
memcpy(fragments, data, size);
|
|
|
|
glyph_cache_fragment_put(glyph_cache, id, size, fragments);
|
2011-11-09 08:26:44 +04:00
|
|
|
|
|
|
|
index += 3;
|
|
|
|
length -= index;
|
|
|
|
data = &(data[index]);
|
|
|
|
index = 0;
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2011-11-22 03:11:43 +04:00
|
|
|
update_process_glyph(context, data, &index, &x, &y, cacheId, ulCharInc, flAccel);
|
2011-11-09 21:16:09 +04:00
|
|
|
index++;
|
2011-11-09 08:26:44 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-12-15 02:08:22 +04:00
|
|
|
if (opWidth > 0 && opHeight > 0)
|
2011-11-22 03:11:43 +04:00
|
|
|
Glyph_EndDraw(context, opX, opY, opWidth, opHeight, bgcolor, fgcolor);
|
2011-11-09 08:26:44 +04:00
|
|
|
else
|
2011-11-22 03:11:43 +04:00
|
|
|
Glyph_EndDraw(context, bkX, bkY, bkWidth, bkHeight, bgcolor, fgcolor);
|
2011-11-09 08:26:44 +04:00
|
|
|
}
|
|
|
|
|
2011-11-22 03:11:43 +04:00
|
|
|
void update_gdi_glyph_index(rdpContext* context, GLYPH_INDEX_ORDER* glyph_index)
|
2011-11-09 08:26:44 +04:00
|
|
|
{
|
2011-11-24 01:11:28 +04:00
|
|
|
rdpGlyphCache* glyph_cache;
|
2011-11-09 08:26:44 +04:00
|
|
|
|
2011-11-24 01:11:28 +04:00
|
|
|
glyph_cache = context->cache->glyph;
|
2013-02-03 21:41:59 +04:00
|
|
|
|
2011-11-24 01:11:28 +04:00
|
|
|
update_process_glyph_fragments(context, glyph_index->data, glyph_index->cbData,
|
|
|
|
glyph_index->cacheId, glyph_index->ulCharInc, glyph_index->flAccel,
|
|
|
|
glyph_index->backColor, glyph_index->foreColor, glyph_index->x, glyph_index->y,
|
|
|
|
glyph_index->bkLeft, glyph_index->bkTop,
|
|
|
|
glyph_index->bkRight - glyph_index->bkLeft, glyph_index->bkBottom - glyph_index->bkTop,
|
|
|
|
glyph_index->opLeft, glyph_index->opTop,
|
|
|
|
glyph_index->opRight - glyph_index->opLeft, glyph_index->opBottom - glyph_index->opTop);
|
2011-11-09 08:26:44 +04:00
|
|
|
}
|
|
|
|
|
2011-11-22 03:11:43 +04:00
|
|
|
void update_gdi_fast_index(rdpContext* context, FAST_INDEX_ORDER* fast_index)
|
2011-11-09 08:26:44 +04:00
|
|
|
{
|
2012-10-09 11:26:39 +04:00
|
|
|
INT32 x, y;
|
2013-02-03 21:41:59 +04:00
|
|
|
INT32 opLeft, opTop;
|
|
|
|
INT32 opRight, opBottom;
|
2011-11-09 08:26:44 +04:00
|
|
|
rdpGlyphCache* glyph_cache;
|
|
|
|
|
2011-11-22 03:11:43 +04:00
|
|
|
glyph_cache = context->cache->glyph;
|
2011-11-09 08:26:44 +04:00
|
|
|
|
2011-11-25 03:32:49 +04:00
|
|
|
opLeft = fast_index->opLeft;
|
|
|
|
opTop = fast_index->opTop;
|
|
|
|
opRight = fast_index->opRight;
|
|
|
|
opBottom = fast_index->opBottom;
|
|
|
|
x = fast_index->x;
|
|
|
|
y = fast_index->y;
|
|
|
|
|
|
|
|
if (opBottom == -32768)
|
|
|
|
{
|
2012-10-09 11:01:37 +04:00
|
|
|
BYTE flags = (BYTE) (opTop & 0x0F);
|
2011-11-25 03:32:49 +04:00
|
|
|
|
|
|
|
if (flags & 0x01)
|
|
|
|
opBottom = fast_index->bkBottom;
|
|
|
|
if (flags & 0x02)
|
|
|
|
opRight = fast_index->bkRight;
|
|
|
|
if (flags & 0x04)
|
|
|
|
opTop = fast_index->bkTop;
|
|
|
|
if (flags & 0x08)
|
|
|
|
opLeft = fast_index->bkLeft;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (opLeft == 0)
|
|
|
|
opLeft = fast_index->bkLeft;
|
|
|
|
|
|
|
|
if (opRight == 0)
|
|
|
|
opRight = fast_index->bkRight;
|
|
|
|
|
|
|
|
if (x == -32768)
|
|
|
|
x = fast_index->bkLeft;
|
|
|
|
|
|
|
|
if (y == -32768)
|
|
|
|
y = fast_index->bkTop;
|
2011-11-09 08:26:44 +04:00
|
|
|
|
2011-11-22 03:11:43 +04:00
|
|
|
update_process_glyph_fragments(context, fast_index->data, fast_index->cbData,
|
2011-11-09 21:16:09 +04:00
|
|
|
fast_index->cacheId, fast_index->ulCharInc, fast_index->flAccel,
|
2011-11-25 03:32:49 +04:00
|
|
|
fast_index->backColor, fast_index->foreColor, x, y,
|
2011-11-09 08:26:44 +04:00
|
|
|
fast_index->bkLeft, fast_index->bkTop,
|
|
|
|
fast_index->bkRight - fast_index->bkLeft, fast_index->bkBottom - fast_index->bkTop,
|
2011-11-25 03:32:49 +04:00
|
|
|
opLeft, opTop,
|
|
|
|
opRight - opLeft, opBottom - opTop);
|
|
|
|
}
|
|
|
|
|
|
|
|
void update_gdi_fast_glyph(rdpContext* context, FAST_GLYPH_ORDER* fast_glyph)
|
|
|
|
{
|
2012-10-09 11:26:39 +04:00
|
|
|
INT32 x, y;
|
2011-11-25 03:32:49 +04:00
|
|
|
rdpGlyph* glyph;
|
2012-10-09 11:01:37 +04:00
|
|
|
BYTE text_data[2];
|
2013-02-03 21:41:59 +04:00
|
|
|
INT32 opLeft, opTop;
|
|
|
|
INT32 opRight, opBottom;
|
|
|
|
GLYPH_DATA_V2* glyph_data;
|
|
|
|
rdpCache* cache = context->cache;
|
2011-11-25 03:32:49 +04:00
|
|
|
|
|
|
|
opLeft = fast_glyph->opLeft;
|
|
|
|
opTop = fast_glyph->opTop;
|
|
|
|
opRight = fast_glyph->opRight;
|
|
|
|
opBottom = fast_glyph->opBottom;
|
|
|
|
x = fast_glyph->x;
|
|
|
|
y = fast_glyph->y;
|
|
|
|
|
|
|
|
if (opBottom == -32768)
|
|
|
|
{
|
2012-10-09 11:01:37 +04:00
|
|
|
BYTE flags = (BYTE) (opTop & 0x0F);
|
2011-11-25 03:32:49 +04:00
|
|
|
|
|
|
|
if (flags & 0x01)
|
|
|
|
opBottom = fast_glyph->bkBottom;
|
|
|
|
if (flags & 0x02)
|
|
|
|
opRight = fast_glyph->bkRight;
|
|
|
|
if (flags & 0x04)
|
|
|
|
opTop = fast_glyph->bkTop;
|
|
|
|
if (flags & 0x08)
|
|
|
|
opLeft = fast_glyph->bkLeft;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (opLeft == 0)
|
|
|
|
opLeft = fast_glyph->bkLeft;
|
|
|
|
|
|
|
|
if (opRight == 0)
|
|
|
|
opRight = fast_glyph->bkRight;
|
|
|
|
|
|
|
|
if (x == -32768)
|
|
|
|
x = fast_glyph->bkLeft;
|
|
|
|
|
|
|
|
if (y == -32768)
|
|
|
|
y = fast_glyph->bkTop;
|
|
|
|
|
2013-02-03 21:41:59 +04:00
|
|
|
if (fast_glyph->cbData > 1)
|
2011-11-25 03:32:49 +04:00
|
|
|
{
|
|
|
|
/* got option font that needs to go into cache */
|
2013-02-03 21:41:59 +04:00
|
|
|
glyph_data = &fast_glyph->glyphData;
|
|
|
|
|
2011-11-25 03:32:49 +04:00
|
|
|
glyph = Glyph_Alloc(context);
|
|
|
|
glyph->x = glyph_data->x;
|
|
|
|
glyph->y = glyph_data->y;
|
|
|
|
glyph->cx = glyph_data->cx;
|
|
|
|
glyph->cy = glyph_data->cy;
|
|
|
|
glyph->cb = glyph_data->cb;
|
2013-02-03 21:41:59 +04:00
|
|
|
glyph->aj = glyph_data->aj;
|
2011-11-25 03:32:49 +04:00
|
|
|
Glyph_New(context, glyph);
|
2013-02-03 21:41:59 +04:00
|
|
|
|
2011-11-25 03:32:49 +04:00
|
|
|
glyph_cache_put(cache->glyph, fast_glyph->cacheId, fast_glyph->data[0], glyph);
|
|
|
|
}
|
|
|
|
|
|
|
|
text_data[0] = fast_glyph->data[0];
|
|
|
|
text_data[1] = 0;
|
|
|
|
|
2011-11-28 02:06:34 +04:00
|
|
|
update_process_glyph_fragments(context, text_data, 1,
|
2011-11-25 03:32:49 +04:00
|
|
|
fast_glyph->cacheId, fast_glyph->ulCharInc, fast_glyph->flAccel,
|
|
|
|
fast_glyph->backColor, fast_glyph->foreColor, x, y,
|
|
|
|
fast_glyph->bkLeft, fast_glyph->bkTop,
|
|
|
|
fast_glyph->bkRight - fast_glyph->bkLeft, fast_glyph->bkBottom - fast_glyph->bkTop,
|
|
|
|
opLeft, opTop,
|
|
|
|
opRight - opLeft, opBottom - opTop);
|
2011-11-09 08:26:44 +04:00
|
|
|
}
|
|
|
|
|
2011-11-22 04:41:49 +04:00
|
|
|
void update_gdi_cache_glyph(rdpContext* context, CACHE_GLYPH_ORDER* cache_glyph)
|
2011-11-09 08:26:44 +04:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
rdpGlyph* glyph;
|
|
|
|
GLYPH_DATA* glyph_data;
|
2011-11-22 04:41:49 +04:00
|
|
|
rdpCache* cache = context->cache;
|
2011-11-09 08:26:44 +04:00
|
|
|
|
2011-12-04 02:24:18 +04:00
|
|
|
for (i = 0; i < (int) cache_glyph->cGlyphs; i++)
|
2011-11-09 08:26:44 +04:00
|
|
|
{
|
2013-01-29 03:42:32 +04:00
|
|
|
glyph_data = &cache_glyph->glyphData[i];
|
2011-11-09 08:26:44 +04:00
|
|
|
|
2011-11-22 04:41:49 +04:00
|
|
|
glyph = Glyph_Alloc(context);
|
2011-11-09 09:43:56 +04:00
|
|
|
|
2011-11-09 08:26:44 +04:00
|
|
|
glyph->x = glyph_data->x;
|
|
|
|
glyph->y = glyph_data->y;
|
|
|
|
glyph->cx = glyph_data->cx;
|
|
|
|
glyph->cy = glyph_data->cy;
|
|
|
|
glyph->cb = glyph_data->cb;
|
2013-02-03 21:41:59 +04:00
|
|
|
glyph->aj = glyph_data->aj;
|
2011-11-22 04:41:49 +04:00
|
|
|
Glyph_New(context, glyph);
|
2011-11-09 08:26:44 +04:00
|
|
|
|
|
|
|
glyph_cache_put(cache->glyph, cache_glyph->cacheId, glyph_data->cacheIndex, glyph);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-11-22 04:41:49 +04:00
|
|
|
void update_gdi_cache_glyph_v2(rdpContext* context, CACHE_GLYPH_V2_ORDER* cache_glyph_v2)
|
2011-11-09 08:26:44 +04:00
|
|
|
{
|
2012-01-05 05:20:58 +04:00
|
|
|
int i;
|
|
|
|
rdpGlyph* glyph;
|
|
|
|
GLYPH_DATA_V2* glyph_data;
|
|
|
|
rdpCache* cache = context->cache;
|
2011-11-09 08:26:44 +04:00
|
|
|
|
2012-01-05 05:20:58 +04:00
|
|
|
for (i = 0; i < (int) cache_glyph_v2->cGlyphs; i++)
|
|
|
|
{
|
2013-01-29 03:42:32 +04:00
|
|
|
glyph_data = &cache_glyph_v2->glyphData[i];
|
2012-01-05 05:20:58 +04:00
|
|
|
|
|
|
|
glyph = Glyph_Alloc(context);
|
|
|
|
|
|
|
|
glyph->x = glyph_data->x;
|
|
|
|
glyph->y = glyph_data->y;
|
|
|
|
glyph->cx = glyph_data->cx;
|
|
|
|
glyph->cy = glyph_data->cy;
|
|
|
|
glyph->cb = glyph_data->cb;
|
2013-02-03 21:41:59 +04:00
|
|
|
glyph->aj = glyph_data->aj;
|
2012-01-05 05:20:58 +04:00
|
|
|
Glyph_New(context, glyph);
|
|
|
|
|
|
|
|
glyph_cache_put(cache->glyph, cache_glyph_v2->cacheId, glyph_data->cacheIndex, glyph);
|
|
|
|
}
|
2011-11-09 08:26:44 +04:00
|
|
|
}
|
|
|
|
|
2012-10-09 11:26:39 +04:00
|
|
|
rdpGlyph* glyph_cache_get(rdpGlyphCache* glyph_cache, UINT32 id, UINT32 index)
|
2011-11-09 08:26:44 +04:00
|
|
|
{
|
2011-11-09 21:57:31 +04:00
|
|
|
rdpGlyph* glyph;
|
2011-08-21 22:16:53 +04:00
|
|
|
|
|
|
|
if (id > 9)
|
|
|
|
{
|
2013-03-29 02:06:34 +04:00
|
|
|
fprintf(stderr, "invalid glyph cache id: %d\n", id);
|
2011-08-21 22:16:53 +04:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2011-11-09 08:26:44 +04:00
|
|
|
if (index > glyph_cache->glyphCache[id].number)
|
2011-08-21 22:16:53 +04:00
|
|
|
{
|
2013-03-29 02:06:34 +04:00
|
|
|
fprintf(stderr, "invalid glyph cache index: %d in cache id: %d\n", index, id);
|
2011-08-21 22:16:53 +04:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2011-11-09 21:57:31 +04:00
|
|
|
glyph = glyph_cache->glyphCache[id].entries[index];
|
|
|
|
|
|
|
|
if (glyph == NULL)
|
|
|
|
{
|
2013-03-29 02:06:34 +04:00
|
|
|
fprintf(stderr, "invalid glyph at cache index: %d in cache id: %d\n", index, id);
|
2011-11-09 21:57:31 +04:00
|
|
|
}
|
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
|
|
|
}
|
|
|
|
|
2012-10-09 11:26:39 +04:00
|
|
|
void glyph_cache_put(rdpGlyphCache* glyph_cache, UINT32 id, UINT32 index, rdpGlyph* glyph)
|
2011-08-21 22:16:53 +04:00
|
|
|
{
|
2011-11-09 09:43:56 +04:00
|
|
|
rdpGlyph* prevGlyph;
|
|
|
|
|
2011-08-21 22:16:53 +04:00
|
|
|
if (id > 9)
|
|
|
|
{
|
2013-03-29 02:06:34 +04:00
|
|
|
fprintf(stderr, "invalid glyph cache id: %d\n", id);
|
2011-08-21 22:16:53 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-11-09 08:26:44 +04:00
|
|
|
if (index > glyph_cache->glyphCache[id].number)
|
2011-08-21 22:16:53 +04:00
|
|
|
{
|
2013-03-29 02:06:34 +04:00
|
|
|
fprintf(stderr, "invalid glyph cache index: %d in cache id: %d\n", index, id);
|
2011-08-21 22:16:53 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-11-09 09:43:56 +04:00
|
|
|
prevGlyph = glyph_cache->glyphCache[id].entries[index];
|
|
|
|
|
|
|
|
if (prevGlyph != NULL)
|
|
|
|
{
|
2012-01-16 00:35:08 +04:00
|
|
|
Glyph_Free(glyph_cache->context, prevGlyph);
|
2012-10-09 07:21:26 +04:00
|
|
|
free(prevGlyph->aj);
|
|
|
|
free(prevGlyph);
|
2011-11-09 09:43:56 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
glyph_cache->glyphCache[id].entries[index] = glyph;
|
2011-08-21 22:16:53 +04:00
|
|
|
}
|
|
|
|
|
2012-10-09 11:26:39 +04:00
|
|
|
void* glyph_cache_fragment_get(rdpGlyphCache* glyph_cache, UINT32 index, UINT32* size)
|
2011-09-19 02:29:23 +04:00
|
|
|
{
|
2011-11-09 21:16:09 +04:00
|
|
|
void* fragment;
|
2011-09-19 02:29:23 +04:00
|
|
|
|
2011-11-09 21:16:09 +04:00
|
|
|
fragment = glyph_cache->fragCache.entries[index].fragment;
|
2012-10-09 11:01:37 +04:00
|
|
|
*size = (BYTE) glyph_cache->fragCache.entries[index].size;
|
2011-09-19 02:29:23 +04:00
|
|
|
|
2011-11-09 21:57:31 +04:00
|
|
|
if (fragment == NULL)
|
|
|
|
{
|
2013-03-29 02:06:34 +04:00
|
|
|
fprintf(stderr, "invalid glyph fragment at index:%d\n", 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
|
|
|
}
|
|
|
|
|
2012-10-09 11:26:39 +04:00
|
|
|
void glyph_cache_fragment_put(rdpGlyphCache* glyph_cache, UINT32 index, UINT32 size, void* fragment)
|
2011-11-09 08:26:44 +04:00
|
|
|
{
|
2011-11-09 21:57:31 +04:00
|
|
|
void* prevFragment;
|
|
|
|
|
|
|
|
prevFragment = glyph_cache->fragCache.entries[index].fragment;
|
|
|
|
|
2011-11-09 21:16:09 +04:00
|
|
|
glyph_cache->fragCache.entries[index].fragment = fragment;
|
2011-11-09 08:26:44 +04:00
|
|
|
glyph_cache->fragCache.entries[index].size = size;
|
2011-11-09 21:57:31 +04:00
|
|
|
|
|
|
|
if (prevFragment != NULL)
|
|
|
|
{
|
2012-10-09 07:21:26 +04:00
|
|
|
free(prevFragment);
|
2011-11-09 21:57:31 +04:00
|
|
|
}
|
2011-11-09 08:26:44 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void glyph_cache_register_callbacks(rdpUpdate* update)
|
2011-09-19 02:29:23 +04:00
|
|
|
{
|
2011-11-22 03:11:43 +04:00
|
|
|
update->primary->GlyphIndex = update_gdi_glyph_index;
|
|
|
|
update->primary->FastIndex = update_gdi_fast_index;
|
2011-11-25 03:32:49 +04:00
|
|
|
update->primary->FastGlyph = update_gdi_fast_glyph;
|
2011-11-22 04:41:49 +04:00
|
|
|
update->secondary->CacheGlyph = update_gdi_cache_glyph;
|
|
|
|
update->secondary->CacheGlyphV2 = update_gdi_cache_glyph_v2;
|
2011-09-19 02:29:23 +04:00
|
|
|
}
|
|
|
|
|
2011-10-12 02:51:45 +04:00
|
|
|
rdpGlyphCache* glyph_cache_new(rdpSettings* settings)
|
2011-08-21 22:16:53 +04:00
|
|
|
{
|
2011-10-12 02:51:45 +04:00
|
|
|
rdpGlyphCache* glyph;
|
2011-08-21 22:16:53 +04:00
|
|
|
|
2012-11-20 08:49:08 +04:00
|
|
|
glyph = (rdpGlyphCache*) malloc(sizeof(rdpGlyphCache));
|
|
|
|
ZeroMemory(glyph, sizeof(rdpGlyphCache));
|
2011-08-21 22:16:53 +04:00
|
|
|
|
|
|
|
if (glyph != NULL)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
glyph->settings = settings;
|
2011-11-09 09:43:56 +04:00
|
|
|
glyph->context = ((freerdp*) settings->instance)->update->context;
|
2011-08-21 22:16:53 +04:00
|
|
|
|
|
|
|
for (i = 0; i < 10; i++)
|
|
|
|
{
|
2012-11-08 00:13:14 +04:00
|
|
|
glyph->glyphCache[i].number = settings->GlyphCache[i].cacheEntries;
|
|
|
|
glyph->glyphCache[i].maxCellSize = settings->GlyphCache[i].cacheMaximumCellSize;
|
2012-11-20 08:49:08 +04:00
|
|
|
glyph->glyphCache[i].entries = (rdpGlyph**) malloc(sizeof(rdpGlyph*) * glyph->glyphCache[i].number);
|
|
|
|
ZeroMemory(glyph->glyphCache[i].entries, sizeof(rdpGlyph*) * glyph->glyphCache[i].number);
|
2011-08-21 22:16:53 +04:00
|
|
|
}
|
|
|
|
|
2012-11-20 08:49:08 +04:00
|
|
|
glyph->fragCache.entries = malloc(sizeof(FRAGMENT_CACHE_ENTRY) * 256);
|
|
|
|
ZeroMemory(glyph->fragCache.entries, sizeof(FRAGMENT_CACHE_ENTRY) * 256);
|
2011-08-21 22:16:53 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return glyph;
|
|
|
|
}
|
|
|
|
|
2012-01-16 00:35:08 +04:00
|
|
|
void glyph_cache_free(rdpGlyphCache* glyph_cache)
|
2011-08-21 22:16:53 +04:00
|
|
|
{
|
2012-01-16 00:35:08 +04:00
|
|
|
if (glyph_cache != NULL)
|
2011-08-21 22:16:53 +04:00
|
|
|
{
|
|
|
|
int i;
|
2012-01-16 00:35:08 +04:00
|
|
|
void* fragment;
|
2011-08-21 22:16:53 +04:00
|
|
|
|
|
|
|
for (i = 0; i < 10; i++)
|
|
|
|
{
|
2012-01-16 00:35:08 +04:00
|
|
|
int j;
|
|
|
|
|
2012-01-16 20:40:18 +04:00
|
|
|
for (j = 0; j < (int) glyph_cache->glyphCache[i].number; j++)
|
2012-01-16 00:35:08 +04:00
|
|
|
{
|
|
|
|
rdpGlyph* glyph;
|
|
|
|
|
|
|
|
glyph = glyph_cache->glyphCache[i].entries[j];
|
2012-02-02 03:42:20 +04:00
|
|
|
|
2012-01-16 00:35:08 +04:00
|
|
|
if (glyph != NULL)
|
|
|
|
{
|
|
|
|
Glyph_Free(glyph_cache->context, glyph);
|
2012-10-09 07:21:26 +04:00
|
|
|
free(glyph->aj);
|
|
|
|
free(glyph);
|
2013-06-28 17:18:20 +04:00
|
|
|
glyph_cache->glyphCache[i].entries[j] = NULL;
|
2012-01-16 00:35:08 +04:00
|
|
|
}
|
|
|
|
}
|
2012-10-09 07:21:26 +04:00
|
|
|
free(glyph_cache->glyphCache[i].entries);
|
2011-08-21 22:16:53 +04:00
|
|
|
}
|
|
|
|
|
2012-01-16 00:35:08 +04:00
|
|
|
for (i = 0; i < 255; i++)
|
|
|
|
{
|
|
|
|
fragment = glyph_cache->fragCache.entries[i].fragment;
|
2012-10-09 07:21:26 +04:00
|
|
|
free(fragment);
|
2013-06-28 17:18:20 +04:00
|
|
|
glyph_cache->fragCache.entries[i].fragment = NULL;
|
2012-01-16 00:35:08 +04:00
|
|
|
}
|
2011-08-21 22:16:53 +04:00
|
|
|
|
2012-10-09 07:21:26 +04:00
|
|
|
free(glyph_cache->fragCache.entries);
|
|
|
|
free(glyph_cache);
|
2011-08-21 22:16:53 +04:00
|
|
|
}
|
|
|
|
}
|