1
/**************************************************************************/
3
/* Copyright (c) 2001, 2007 NoMachine, http://www.nomachine.com/. */
5
/* NXCOMP, NX protocol compression and NX extensions to this software */
6
/* are copyright of NoMachine. Redistribution and use of the present */
7
/* software is allowed according to terms specified in the file LICENSE */
8
/* which comes in the source distribution. */
10
/* Check http://www.nomachine.com/licensing.html for applicability. */
12
/* NX and NoMachine are trademarks of NoMachine S.r.l. */
14
/* All rights reserved. */
16
/**************************************************************************/
19
// Include the template for
20
// this message class.
23
#include "RenderCompositeGlyphs.h"
26
// Set the verbosity level.
37
// Message handling methods.
40
MESSAGE_BEGIN_ENCODE_SIZE
42
ClientCache *clientCache = (ClientCache *) channelCache;
45
*logofs << name() << ": Encoding value "
46
<< ((size - MESSAGE_OFFSET) >> 2) << ".\n"
50
encodeBuffer.encodeCachedValue((size - MESSAGE_OFFSET) >> 2, 16,
51
clientCache -> renderLengthCache, 5);
54
*logofs << name() << ": Encoded size with value "
55
<< size << ".\n" << logofs_flush;
58
MESSAGE_END_ENCODE_SIZE
60
MESSAGE_BEGIN_DECODE_SIZE
62
ClientCache *clientCache = (ClientCache *) channelCache;
64
decodeBuffer.decodeCachedValue(size, 16,
65
clientCache -> renderLengthCache, 5);
68
*logofs << name() << ": Decoded value " << size
69
<< ".\n" << logofs_flush;
72
size = MESSAGE_OFFSET + (size << 2);
74
buffer = writeBuffer -> addMessage(size);
77
*logofs << name() << ": Decoded size with value "
78
<< size << ".\n" << logofs_flush;
81
MESSAGE_END_DECODE_SIZE
83
MESSAGE_BEGIN_ENCODE_MESSAGE
85
ClientCache *clientCache = (ClientCache *) channelCache;
87
encodeBuffer.encodeCachedValue(*(buffer + 4), 8,
88
clientCache -> renderOpCache);
90
encodeBuffer.encodeXidValue(GetULONG(buffer + 8, bigEndian),
91
clientCache -> renderSrcPictureCache);
93
encodeBuffer.encodeXidValue(GetULONG(buffer + 12, bigEndian),
94
clientCache -> renderDstPictureCache);
96
encodeBuffer.encodeCachedValue(GetULONG(buffer + 16, bigEndian), 32,
97
clientCache -> renderFormatCache);
99
encodeBuffer.encodeCachedValue(GetULONG(buffer + 20, bigEndian), 29,
100
clientCache -> renderGlyphSetCache);
102
unsigned int src_x = GetUINT(buffer + 24, bigEndian);
103
unsigned int src_y = GetUINT(buffer + 26, bigEndian);
105
if (control -> isProtoStep8() == 1)
107
encodeBuffer.encodeDiffCachedValue(src_x,
108
clientCache -> renderGlyphX, 16,
109
clientCache -> renderGlyphXCache, 11);
111
encodeBuffer.encodeDiffCachedValue(src_y,
112
clientCache -> renderGlyphY, 16,
113
clientCache -> renderGlyphYCache, 11);
117
encodeBuffer.encodeDiffCachedValue(src_x,
118
clientCache -> renderLastX, 16,
119
clientCache -> renderXCache, 11);
121
encodeBuffer.encodeDiffCachedValue(src_y,
122
clientCache -> renderLastY, 16,
123
clientCache -> renderYCache, 11);
127
*logofs << name() << ": Encoded source X "
128
<< GetUINT(buffer + 24, bigEndian) << " source Y "
129
<< GetUINT(buffer + 26, bigEndian) << ".\n"
134
// Bytes from 28 to 36 contain in the order:
136
// 1 byte for the length of the first string.
137
// 3 bytes of padding.
138
// 2 bytes for the X offset.
139
// 2 bytes for the Y offset.
141
// Encode these bytes differentially to match
142
// all the strings that have equal glyphs.
144
// Only manage the first string of glyphs. The
145
// others strings should match, if they contain
146
// the same glyphs, since the offset are rela-
147
// tive to the first offset coordinates.
150
if (control -> isProtoStep8() == 1 &&
151
size >= MESSAGE_OFFSET_IF_PROTO_STEP_8)
153
unsigned int numGlyphs = *(buffer + 28);
155
encodeBuffer.encodeCachedValue(numGlyphs, 8,
156
clientCache -> renderNumGlyphsCache);
158
unsigned int offset_x = GetUINT(buffer + 32, bigEndian);
159
unsigned int offset_y = GetUINT(buffer + 34, bigEndian);
161
if (offset_x == src_x && offset_y == src_y)
163
encodeBuffer.encodeBoolValue(0);
166
*logofs << name() << ": Matched offset X "
167
<< GetUINT(buffer + 32, bigEndian) << " offset Y "
168
<< GetUINT(buffer + 34, bigEndian) << ".\n"
174
encodeBuffer.encodeBoolValue(1);
176
encodeBuffer.encodeDiffCachedValue(offset_x,
177
clientCache -> renderGlyphX, 16,
178
clientCache -> renderGlyphXCache, 11);
180
encodeBuffer.encodeDiffCachedValue(offset_y,
181
clientCache -> renderGlyphY, 16,
182
clientCache -> renderGlyphYCache, 11);
185
*logofs << name() << ": Missed offset X "
186
<< GetUINT(buffer + 32, bigEndian) << " offset Y "
187
<< GetUINT(buffer + 34, bigEndian) << ".\n"
194
*logofs << name() << ": Encoded message. Type is "
195
<< (unsigned int) *(buffer + 1) << " size is "
196
<< size << ".\n" << logofs_flush;
199
MESSAGE_END_ENCODE_MESSAGE
201
MESSAGE_BEGIN_DECODE_MESSAGE
203
ClientCache *clientCache = (ClientCache *) channelCache;
207
*(buffer + 1) = type;
209
decodeBuffer.decodeCachedValue(*(buffer + 4), 8,
210
clientCache -> renderOpCache);
212
decodeBuffer.decodeXidValue(value,
213
clientCache -> renderSrcPictureCache);
215
PutULONG(value, buffer + 8, bigEndian);
217
decodeBuffer.decodeXidValue(value,
218
clientCache -> renderDstPictureCache);
220
PutULONG(value, buffer + 12, bigEndian);
222
decodeBuffer.decodeCachedValue(value, 32,
223
clientCache -> renderFormatCache);
225
PutULONG(value, buffer + 16, bigEndian);
227
decodeBuffer.decodeCachedValue(value, 29,
228
clientCache -> renderGlyphSetCache);
230
PutULONG(value, buffer + 20, bigEndian);
235
if (control -> isProtoStep8() == 1)
237
decodeBuffer.decodeDiffCachedValue(src_x,
238
clientCache -> renderGlyphX, 16,
239
clientCache -> renderGlyphXCache, 11);
241
decodeBuffer.decodeDiffCachedValue(src_y,
242
clientCache -> renderGlyphY, 16,
243
clientCache -> renderGlyphYCache, 11);
247
decodeBuffer.decodeDiffCachedValue(src_x,
248
clientCache -> renderLastX, 16,
249
clientCache -> renderXCache, 11);
251
decodeBuffer.decodeDiffCachedValue(src_y,
252
clientCache -> renderLastY, 16,
253
clientCache -> renderYCache, 11);
256
PutUINT(src_x, buffer + 24, bigEndian);
257
PutUINT(src_y, buffer + 26, bigEndian);
259
if (control -> isProtoStep8() == 1 &&
260
size >= MESSAGE_OFFSET_IF_PROTO_STEP_8)
262
decodeBuffer.decodeCachedValue(value, 8,
263
clientCache -> renderNumGlyphsCache);
265
*(buffer + 28) = value;
267
decodeBuffer.decodeBoolValue(value);
271
PutUINT(src_x, buffer + 32, bigEndian);
272
PutUINT(src_y, buffer + 34, bigEndian);
276
decodeBuffer.decodeDiffCachedValue(src_x,
277
clientCache -> renderGlyphX, 16,
278
clientCache -> renderGlyphXCache, 11);
280
PutUINT(src_x, buffer + 32, bigEndian);
282
decodeBuffer.decodeDiffCachedValue(src_y,
283
clientCache -> renderGlyphY, 16,
284
clientCache -> renderGlyphYCache, 11);
286
PutUINT(src_y, buffer + 34, bigEndian);
291
*logofs << name() << ": Decoded message. Type is "
292
<< (unsigned int) type << " size is " << size
293
<< ".\n" << logofs_flush;
296
MESSAGE_END_DECODE_MESSAGE
298
MESSAGE_BEGIN_ENCODE_DATA
300
if (control -> isProtoStep8() == 1 &&
301
size >= MESSAGE_OFFSET_IF_PROTO_STEP_8)
303
encodeCharData(encodeBuffer, buffer, MESSAGE_OFFSET_IF_PROTO_STEP_8,
304
size, bigEndian, channelCache);
306
else if (size > MESSAGE_OFFSET)
308
encodeCharData(encodeBuffer, buffer, MESSAGE_OFFSET,
309
size, bigEndian, channelCache);
313
*logofs << name() << ": Encoded " << size - MESSAGE_OFFSET
314
<< " bytes of text data.\n" << logofs_flush;
317
MESSAGE_END_ENCODE_DATA
319
MESSAGE_BEGIN_DECODE_DATA
321
if (control -> isProtoStep8() == 1 &&
322
size >= MESSAGE_OFFSET_IF_PROTO_STEP_8)
324
decodeCharData(decodeBuffer, buffer, MESSAGE_OFFSET_IF_PROTO_STEP_8,
325
size, bigEndian, channelCache);
327
else if (size > MESSAGE_OFFSET)
329
decodeCharData(decodeBuffer, buffer, MESSAGE_OFFSET,
330
size, bigEndian, channelCache);
334
*logofs << name() << ": Decoded " << size - MESSAGE_OFFSET
335
<< " bytes of data.\n" << logofs_flush;
338
MESSAGE_END_DECODE_DATA
340
MESSAGE_BEGIN_PARSE_IDENTITY
342
RenderExtensionMessage *renderExtension = (RenderExtensionMessage *) message;
344
renderExtension -> data.composite_glyphs.type = *(buffer + 1);
345
renderExtension -> data.composite_glyphs.op = *(buffer + 4);
347
renderExtension -> data.composite_glyphs.src_id = GetULONG(buffer + 8, bigEndian);
348
renderExtension -> data.composite_glyphs.dst_id = GetULONG(buffer + 12, bigEndian);
350
renderExtension -> data.composite_glyphs.format = GetULONG(buffer + 16, bigEndian);
351
renderExtension -> data.composite_glyphs.set_id = GetULONG(buffer + 20, bigEndian);
353
renderExtension -> data.composite_glyphs.src_x = GetUINT(buffer + 24, bigEndian);
354
renderExtension -> data.composite_glyphs.src_y = GetUINT(buffer + 26, bigEndian);
356
if (control -> isProtoStep8() == 1 &&
357
size >= MESSAGE_OFFSET_IF_PROTO_STEP_8)
359
renderExtension -> data.composite_glyphs.num_elm = *(buffer + 28);
361
renderExtension -> data.composite_glyphs.offset_x = GetUINT(buffer + 32, bigEndian);
362
renderExtension -> data.composite_glyphs.offset_y = GetUINT(buffer + 34, bigEndian);
366
*logofs << name() << ": Parsed identity. Type is "
367
<< (unsigned int) renderExtension -> data.composite_glyphs.type
368
<< " size is " << renderExtension -> size_ << " identity size "
369
<< renderExtension -> i_size_ << ".\n" << logofs_flush;
372
MESSAGE_END_PARSE_IDENTITY
374
MESSAGE_BEGIN_UNPARSE_IDENTITY
376
RenderExtensionMessage *renderExtension = (RenderExtensionMessage *) message;
378
*(buffer + 1) = renderExtension -> data.composite_glyphs.type;
379
*(buffer + 4) = renderExtension -> data.composite_glyphs.op;
381
PutULONG(renderExtension -> data.composite_glyphs.src_id, buffer + 8, bigEndian);
382
PutULONG(renderExtension -> data.composite_glyphs.dst_id, buffer + 12, bigEndian);
384
PutULONG(renderExtension -> data.composite_glyphs.format, buffer + 16, bigEndian);
385
PutULONG(renderExtension -> data.composite_glyphs.set_id, buffer + 20, bigEndian);
387
PutUINT(renderExtension -> data.composite_glyphs.src_x, buffer + 24, bigEndian);
388
PutUINT(renderExtension -> data.composite_glyphs.src_y, buffer + 26, bigEndian);
390
if (control -> isProtoStep8() == 1 &&
391
size >= MESSAGE_OFFSET_IF_PROTO_STEP_8)
393
*(buffer + 28) = renderExtension -> data.composite_glyphs.num_elm;
395
PutUINT(renderExtension -> data.composite_glyphs.offset_x, buffer + 32, bigEndian);
396
PutUINT(renderExtension -> data.composite_glyphs.offset_y, buffer + 34, bigEndian);
400
*logofs << name() << ": Unparsed identity. Type is "
401
<< (unsigned int) renderExtension -> data.composite_glyphs.type
402
<< " size is " << renderExtension -> size_ << " identity size "
403
<< renderExtension -> i_size_ << ".\n" << logofs_flush;
406
MESSAGE_END_UNPARSE_IDENTITY
408
MESSAGE_BEGIN_IDENTITY_CHECKSUM
411
// Include minor opcode, size and
412
// the composite operator in the
416
md5_append(md5_state, buffer + 1, 4);
419
// Include the format.
422
md5_append(md5_state, buffer + 16, 4);
425
// Also include the length of the
429
if (control -> isProtoStep8() == 1 &&
430
size >= MESSAGE_OFFSET_IF_PROTO_STEP_8)
432
md5_append(md5_state, buffer + 28, 1);
435
MESSAGE_END_IDENTITY_CHECKSUM
437
MESSAGE_BEGIN_ENCODE_UPDATE
439
RenderExtensionMessage *renderExtension = (RenderExtensionMessage *) message;
440
RenderExtensionMessage *cachedRenderExtension = (RenderExtensionMessage *) cachedMessage;
442
ClientCache *clientCache = (ClientCache *) channelCache;
444
encodeBuffer.encodeXidValue(renderExtension -> data.composite_glyphs.src_id,
445
clientCache -> renderSrcPictureCache);
447
cachedRenderExtension -> data.composite_glyphs.src_id =
448
renderExtension -> data.composite_glyphs.src_id;
450
encodeBuffer.encodeXidValue(renderExtension -> data.composite_glyphs.dst_id,
451
clientCache -> renderDstPictureCache);
453
cachedRenderExtension -> data.composite_glyphs.dst_id =
454
renderExtension -> data.composite_glyphs.dst_id;
456
encodeBuffer.encodeCachedValue(renderExtension -> data.composite_glyphs.set_id, 29,
457
clientCache -> renderGlyphSetCache);
459
cachedRenderExtension -> data.composite_glyphs.set_id =
460
renderExtension -> data.composite_glyphs.set_id;
465
// The source X and Y coordinates are
466
// encoded as differerences in respect
467
// to the cached message.
471
unsigned int previous;
473
if (control -> isProtoStep8() == 1)
475
value = renderExtension -> data.composite_glyphs.src_x;
476
previous = cachedRenderExtension -> data.composite_glyphs.src_x;
478
encodeBuffer.encodeDiffCachedValue(value, previous, 16,
479
clientCache -> renderGlyphXCache, 11);
481
cachedRenderExtension -> data.composite_glyphs.src_x = value;
483
value = renderExtension -> data.composite_glyphs.src_y;
484
previous = cachedRenderExtension -> data.composite_glyphs.src_y;
486
encodeBuffer.encodeDiffCachedValue(value, previous, 16,
487
clientCache -> renderGlyphYCache, 11);
489
cachedRenderExtension -> data.composite_glyphs.src_y = value;
493
value = renderExtension -> data.composite_glyphs.src_x;
494
previous = cachedRenderExtension -> data.composite_glyphs.src_x;
496
encodeBuffer.encodeDiffCachedValue(value, previous, 16,
497
clientCache -> renderXCache, 11);
499
cachedRenderExtension -> data.composite_glyphs.src_x = value;
501
value = renderExtension -> data.composite_glyphs.src_y;
502
previous = cachedRenderExtension -> data.composite_glyphs.src_y;
504
encodeBuffer.encodeDiffCachedValue(value, previous, 16,
505
clientCache -> renderYCache, 11);
507
cachedRenderExtension -> data.composite_glyphs.src_y = value;
511
*logofs << name() << ": Encoded source X "
512
<< renderExtension -> data.composite_glyphs.src_x << " source Y "
513
<< renderExtension -> data.composite_glyphs.src_y << ".\n"
517
if (control -> isProtoStep8() == 1 &&
518
renderExtension -> size_ >= MESSAGE_OFFSET_IF_PROTO_STEP_8)
524
if (renderExtension -> data.composite_glyphs.offset_x ==
525
renderExtension -> data.composite_glyphs.src_x &&
526
renderExtension -> data.composite_glyphs.offset_y ==
527
renderExtension -> data.composite_glyphs.src_y)
529
encodeBuffer.encodeBoolValue(0);
531
cachedRenderExtension -> data.composite_glyphs.offset_x =
532
renderExtension -> data.composite_glyphs.offset_x;
534
cachedRenderExtension -> data.composite_glyphs.offset_y =
535
renderExtension -> data.composite_glyphs.offset_y;
538
*logofs << name() << ": Matched offset X "
539
<< renderExtension -> data.composite_glyphs.offset_x << " offset Y "
540
<< renderExtension -> data.composite_glyphs.offset_y << ".\n"
546
encodeBuffer.encodeBoolValue(1);
548
value = renderExtension -> data.composite_glyphs.offset_x;
549
previous = cachedRenderExtension -> data.composite_glyphs.offset_x;
551
encodeBuffer.encodeDiffCachedValue(value, previous, 16,
552
clientCache -> renderGlyphXCache, 11);
554
cachedRenderExtension -> data.composite_glyphs.offset_x = value;
556
value = renderExtension -> data.composite_glyphs.offset_y;
557
previous = cachedRenderExtension -> data.composite_glyphs.offset_y;
559
encodeBuffer.encodeDiffCachedValue(value, previous, 16,
560
clientCache -> renderGlyphYCache, 11);
562
cachedRenderExtension -> data.composite_glyphs.offset_y = value;
565
*logofs << name() << ": Missed offset X "
566
<< renderExtension -> data.composite_glyphs.offset_x << " offset Y "
567
<< renderExtension -> data.composite_glyphs.offset_y << ".\n"
574
*logofs << name() << ": Encoded update. Type is "
575
<< (unsigned int) renderExtension -> data.composite_glyphs.type
576
<< " size is " << renderExtension -> size_ << ".\n"
580
MESSAGE_END_ENCODE_UPDATE
582
MESSAGE_BEGIN_DECODE_UPDATE
584
RenderExtensionMessage *renderExtension = (RenderExtensionMessage *) message;
586
ClientCache *clientCache = (ClientCache *) channelCache;
588
decodeBuffer.decodeXidValue(renderExtension -> data.composite_glyphs.src_id,
589
clientCache -> renderSrcPictureCache);
591
decodeBuffer.decodeXidValue(renderExtension -> data.composite_glyphs.dst_id,
592
clientCache -> renderDstPictureCache);
594
decodeBuffer.decodeCachedValue(renderExtension -> data.composite_glyphs.set_id, 29,
595
clientCache -> renderGlyphSetCache);
602
unsigned int previous;
604
if (control -> isProtoStep8() == 1)
606
previous = renderExtension -> data.composite_glyphs.src_x;
608
decodeBuffer.decodeDiffCachedValue(value, previous, 16,
609
clientCache -> renderGlyphXCache, 11);
611
renderExtension -> data.composite_glyphs.src_x = value;
613
previous = renderExtension -> data.composite_glyphs.src_y;
615
decodeBuffer.decodeDiffCachedValue(value, previous, 16,
616
clientCache -> renderGlyphYCache, 11);
618
renderExtension -> data.composite_glyphs.src_y = value;
622
previous = renderExtension -> data.composite_glyphs.src_x;
624
decodeBuffer.decodeDiffCachedValue(value, previous, 16,
625
clientCache -> renderXCache, 11);
627
renderExtension -> data.composite_glyphs.src_x = value;
629
previous = renderExtension -> data.composite_glyphs.src_y;
631
decodeBuffer.decodeDiffCachedValue(value, previous, 16,
632
clientCache -> renderYCache, 11);
634
renderExtension -> data.composite_glyphs.src_y = value;
637
if (control -> isProtoStep8() == 1 &&
638
renderExtension -> size_ >= MESSAGE_OFFSET_IF_PROTO_STEP_8)
644
decodeBuffer.decodeBoolValue(value);
648
renderExtension -> data.composite_glyphs.offset_x =
649
renderExtension -> data.composite_glyphs.src_x;
651
renderExtension -> data.composite_glyphs.offset_y =
652
renderExtension -> data.composite_glyphs.src_y;
656
previous = renderExtension -> data.composite_glyphs.offset_x;
658
decodeBuffer.decodeDiffCachedValue(value, previous, 16,
659
clientCache -> renderGlyphXCache, 11);
661
renderExtension -> data.composite_glyphs.offset_x = value;
663
previous = renderExtension -> data.composite_glyphs.offset_y;
665
decodeBuffer.decodeDiffCachedValue(value, previous, 16,
666
clientCache -> renderGlyphYCache, 11);
668
renderExtension -> data.composite_glyphs.offset_y = value;
673
*logofs << name() << ": Decoded update. Type is "
674
<< (unsigned int) renderExtension -> data.composite_glyphs.type
675
<< " size is " << renderExtension -> size_ << ".\n"
679
MESSAGE_END_DECODE_UPDATE