1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
|
/* $Xorg: mediaSizes.c,v 1.4 2001/03/14 18:44:37 pookie Exp $ */
/*
(c) Copyright 1996 Hewlett-Packard Company
(c) Copyright 1996 International Business Machines Corp.
(c) Copyright 1996 Sun Microsystems, Inc.
(c) Copyright 1996 Novell, Inc.
(c) Copyright 1996 Digital Equipment Corp.
(c) Copyright 1996 Fujitsu Limited
(c) Copyright 1996 Hitachi, Ltd.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Except as contained in this notice, the names of the copyright holders shall
not be used in advertising or otherwise to promote the sale, use or other
dealings in this Software without prior written authorization from said
copyright holders.
*/
/*******************************************************************
**
** *********************************************************
** *
** * File: mediaSizes.c
** *
** * Contents:
** * Routines to return the sizes associated
** * with particular media and particular printers.
** *
** * Created: 2/19/96
** *
** * Copyright: Copyright 1993,1995 Hewlett-Packard Company
** *
** *********************************************************
**
********************************************************************/
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <ctype.h>
#include <string.h>
#include <locale.h>
#include <X11/X.h>
#include "dixstruct.h"
#include "screenint.h"
#include <X11/misc.h>
#include "scrnintstr.h"
#include "fontstruct.h"
#include "DiPrint.h"
#include "attributes.h"
typedef struct {
XpOid page_size;
float width;
float height;
} PageDimensionsRec;
static PageDimensionsRec PageDimensions[] =
{
{xpoid_val_medium_size_na_letter, 215.9, 279.4},
{xpoid_val_medium_size_na_legal, 215.9, 355.6},
{xpoid_val_medium_size_executive, 184.15, 266.7},
{xpoid_val_medium_size_folio, 210.82, 330.2},
{xpoid_val_medium_size_invoice, 139.7, 215.9},
{xpoid_val_medium_size_ledger, 279.4, 431.8},
{xpoid_val_medium_size_quarto, 215.9, 275.082},
{xpoid_val_medium_size_a, 215.9, 279.4},
{xpoid_val_medium_size_b, 279.4, 431.8},
{xpoid_val_medium_size_c, 431.8, 558.8},
{xpoid_val_medium_size_d, 558.8, 863.6},
{xpoid_val_medium_size_e, 863.6, 1117.6},
{xpoid_val_medium_size_na_6x9_envelope, 152.4, 228.6},
{xpoid_val_medium_size_na_10x15_envelope, 254, 381},
{xpoid_val_medium_size_monarch_envelope, 98.298, 190.5},
{xpoid_val_medium_size_na_10x13_envelope, 254, 330.2},
{xpoid_val_medium_size_na_9x12_envelope, 228.6, 304.8},
{xpoid_val_medium_size_na_number_10_envelope, 104.775, 241.3},
{xpoid_val_medium_size_na_7x9_envelope, 177.8, 228.6},
{xpoid_val_medium_size_na_9x11_envelope, 228.6, 279.4},
{xpoid_val_medium_size_na_10x14_envelope, 254, 355.6},
{xpoid_val_medium_size_na_number_9_envelope, 98.425, 225.425},
{xpoid_val_medium_size_iso_a0, 841, 1189},
{xpoid_val_medium_size_iso_a1, 594, 841},
{xpoid_val_medium_size_iso_a2, 420, 594},
{xpoid_val_medium_size_iso_a3, 297, 420},
{xpoid_val_medium_size_iso_a4, 210, 297},
{xpoid_val_medium_size_iso_a5, 148, 210},
{xpoid_val_medium_size_iso_a6, 105, 148},
{xpoid_val_medium_size_iso_a7, 74, 105},
{xpoid_val_medium_size_iso_a8, 52, 74},
{xpoid_val_medium_size_iso_a9, 37, 52},
{xpoid_val_medium_size_iso_a10, 26, 37},
{xpoid_val_medium_size_iso_b0, 1000, 1414},
{xpoid_val_medium_size_iso_b1, 707, 1000},
{xpoid_val_medium_size_iso_b2, 500, 707},
{xpoid_val_medium_size_iso_b3, 353, 500},
{xpoid_val_medium_size_iso_b4, 250, 353},
{xpoid_val_medium_size_iso_b5, 176, 250},
{xpoid_val_medium_size_iso_b6, 125, 176},
{xpoid_val_medium_size_iso_b7, 88, 125},
{xpoid_val_medium_size_iso_b8, 62, 88},
{xpoid_val_medium_size_iso_b9, 44, 62},
{xpoid_val_medium_size_iso_b10, 31, 44},
{xpoid_val_medium_size_jis_b0, 1030, 1456},
{xpoid_val_medium_size_jis_b1, 728, 1030},
{xpoid_val_medium_size_jis_b2, 515, 728},
{xpoid_val_medium_size_jis_b3, 364, 515},
{xpoid_val_medium_size_jis_b4, 257, 364},
{xpoid_val_medium_size_jis_b5, 182, 257},
{xpoid_val_medium_size_jis_b6, 128, 182},
{xpoid_val_medium_size_jis_b7, 91, 128},
{xpoid_val_medium_size_jis_b8, 64, 91},
{xpoid_val_medium_size_jis_b9, 45, 64},
{xpoid_val_medium_size_jis_b10, 32, 45},
{xpoid_val_medium_size_hp_2x_postcard, 148, 200},
{xpoid_val_medium_size_hp_european_edp, 304.8, 355.6},
{xpoid_val_medium_size_hp_mini, 139.7, 215.9},
{xpoid_val_medium_size_hp_postcard, 100, 148},
{xpoid_val_medium_size_hp_tabloid, 279.4, 431.8},
{xpoid_val_medium_size_hp_us_edp, 279.4, 355.6},
{xpoid_val_medium_size_hp_us_government_legal, 203.2, 330.2},
{xpoid_val_medium_size_hp_us_government_letter, 203.2, 254},
{xpoid_val_medium_size_iso_c3, 324, 458},
{xpoid_val_medium_size_iso_c4, 229, 324},
{xpoid_val_medium_size_iso_c5, 162, 229},
{xpoid_val_medium_size_iso_c6, 114, 162},
{xpoid_val_medium_size_iso_designated_long, 110, 220}
};
/*
* XpGetResolution returns an integer representing the printer resolution
* in dots-per-inch for the specified print context.
*
* Note: This routine assumes the values found in the passed context's
* attributes pools have been validated.
*/
int
XpGetResolution(
XpContextPtr pContext)
{
unsigned long resolution;
resolution = XpGetCardAttr(pContext, XPPageAttr,
xpoid_att_default_printer_resolution,
(XpOidCardList*)NULL);
if(0 == resolution)
resolution = XpGetCardAttr(pContext, XPDocAttr,
xpoid_att_default_printer_resolution,
(XpOidCardList*)NULL);
if(0 == resolution)
{
XpOidCardList* resolutions_supported;
/*
* default-printer-resolution not specified; default to 1st entry
* in printer-resolutions-supported.
*/
resolutions_supported =
XpGetCardListAttr(pContext, XPPrinterAttr,
xpoid_att_printer_resolutions_supported,
(XpOidCardList*)NULL);
resolution = XpOidCardListGetCard(resolutions_supported, 0);
XpOidCardListDelete(resolutions_supported);
}
return (int)resolution;
}
/*
* XpGetContentOrientation determines the content-orientation as
* determined by the passed context. The page and document pools are
* queried in turn for a specified content-orientation attribute. If none
* is found the first content-orientation in the
* content-orientations-supported printer attribute is taken as the
* default.
*
* Note: This routine assumes the values found in the passed context's
* attributes pools have been validated.
*/
XpOid
XpGetContentOrientation(
XpContextPtr pContext)
{
XpOid orientation;
orientation = XpGetOidAttr(pContext, XPPageAttr,
xpoid_att_content_orientation,
(XpOidList*)NULL);
if(xpoid_none == orientation)
orientation = XpGetOidAttr(pContext, XPDocAttr,
xpoid_att_content_orientation,
(XpOidList*)NULL);
if(xpoid_none == orientation)
{
XpOidList* content_orientations_supported;
content_orientations_supported =
XpGetListAttr(pContext, XPPrinterAttr,
xpoid_att_content_orientations_supported,
(XpOidList*)NULL);
orientation = XpOidListGetOid(content_orientations_supported, 0);
XpOidListDelete(content_orientations_supported);
}
return orientation;
}
/*
* XpGetAvailableCompression determines the available-compression as
* determined by the passed context. The page and document pools are
* queried in turn for a specified content-orientation attribute. If none
* is found the first available-compression in the
* avaiable-compressions-supported printer attribute is taken as the
* default.
*
* Note: This routine assumes the values found in the passed context's
* attributes pools have been validated.
*/
XpOid
XpGetAvailableCompression(
XpContextPtr pContext)
{
XpOid compression;
compression = XpGetOidAttr(pContext, XPPageAttr,
xpoid_att_available_compression,
(XpOidList*)NULL);
if(xpoid_none == compression)
compression = XpGetOidAttr(pContext, XPDocAttr,
xpoid_att_available_compression,
(XpOidList*)NULL);
if(xpoid_none == compression)
{
XpOidList* available_compressions_supported;
available_compressions_supported =
XpGetListAttr(pContext, XPPrinterAttr,
xpoid_att_available_compressions_supported,
(XpOidList*)NULL);
compression = XpOidListGetOid(available_compressions_supported, 0);
XpOidListDelete(available_compressions_supported);
}
return compression;
}
/*
* XpGetPlex determines the plex as determined by the passed context. The page
* and document pools are queried in turn for a specified plex attribute. If
* none is found the first plex in the plexes-supported printer attribute is
* taken as the default.
*
* Note: This routine assumes the values found in the passed context's
* attributes pools have been validated.
*/
XpOid
XpGetPlex(
XpContextPtr pContext)
{
XpOid plex;
plex = XpGetOidAttr(pContext, XPPageAttr, xpoid_att_plex,
(XpOidList*)NULL);
if(xpoid_none == plex)
plex = XpGetOidAttr(pContext, XPDocAttr, xpoid_att_plex,
(XpOidList*)NULL);
if(xpoid_none == plex)
{
XpOidList* plexes_supported;
plexes_supported =
XpGetListAttr(pContext, XPPrinterAttr,
xpoid_att_plexes_supported,
(XpOidList*)NULL);
plex = XpOidListGetOid(plexes_supported, 0);
XpOidListDelete(plexes_supported);
}
return plex;
}
/*
* XpGetPageSize returns the XpOid of the current page size (medium names
* are page sizes in this implementation) as indicated by the passed
* context.
*
* The relevant input-tray is returned in pTray. This parm must not be
* NULL. If the input-tray is not indicated or irrelevant, xpoid_none
* will be returned.
*
* This function optionally takes a XpOidMediumSS representation of the
* medium-source-sizes-supported attribute in order to avoid parsing the
* string value twice for calling functions that need to parse m-s-s-s
* anyway (e.g. XpGetReproductionArea). If the caller has no other reason
* to parse medium-source-sizes-supported, it is recommended that NULL be
* passed. This function will obtain medium-source-sizes-supported if it
* needs to.
*
* Note: This routine assumes the values found in the passed context's
* attributes pools have been validated.
*/
XpOid
XpGetPageSize(XpContextPtr pContext,
XpOid* pTray,
const XpOidMediumSS* msss)
{
XpOid medium;
/*
* check to see if default-medium is specified
*/
medium = XpGetOidAttr(pContext, XPPageAttr, xpoid_att_default_medium,
(const XpOidList*)NULL);
if(medium == xpoid_none)
{
/*
* default-medium not in page pool; try the document pool
*/
medium = XpGetOidAttr(pContext, XPDocAttr, xpoid_att_default_medium,
(const XpOidList*)NULL);
}
if(medium == xpoid_none)
{
/*
* default-medium not specified; try default-input-tray
*/
*pTray = XpGetOidAttr(pContext, XPPageAttr,
xpoid_att_default_input_tray,
(const XpOidList*)NULL);
if(*pTray == xpoid_none)
{
/*
* default-input-tray not in page pool; try the document pool
*/
*pTray = XpGetOidAttr(pContext, XPDocAttr,
xpoid_att_default_input_tray,
(const XpOidList*)NULL);
}
if(*pTray != xpoid_none)
{
/*
* default-input-tray found; get corresponding medium from
* input-trays-medium
*/
XpOidTrayMediumList* input_trays_medium;
int i;
input_trays_medium =
XpGetTrayMediumListAttr(pContext, XPPrinterAttr,
xpoid_att_input_trays_medium,
(const XpOidList*)NULL,
(const XpOidMediumSS*)NULL);
for(i = 0; i < XpOidTrayMediumListCount(input_trays_medium); i++)
{
if(*pTray == XpOidTrayMediumListTray(input_trays_medium, i))
{
medium = XpOidTrayMediumListMedium(input_trays_medium, i);
break;
}
}
XpOidTrayMediumListDelete(input_trays_medium);
}
}
else
*pTray = xpoid_none;
if(medium == xpoid_none)
{
XpOidMediumSS* local_msss = (XpOidMediumSS*)NULL;
int i_mss, i_ds;
XpOidMediumDiscreteSizeList* ds_list;
/*
* no medium specified; use 1st page size found in
* medium-source-sizes-supported
*/
if((XpOidMediumSS*)NULL == msss)
msss = local_msss =
XpGetMediumSSAttr(pContext, XPPrinterAttr,
xpoid_att_medium_source_sizes_supported,
(const XpOidList*)NULL,
(const XpOidList*)NULL);
for(i_mss = 0;
i_mss < XpOidMediumSSCount(msss) && xpoid_none == medium;
i_mss++)
{
if(XpOidMediumSS_DISCRETE == (msss->mss)[i_mss].mstag
&&
xpoid_none != (msss->mss)[i_mss].input_tray)
{
ds_list = (msss->mss)[i_mss].ms.discrete;
for(i_ds = 0; i_ds < ds_list->count; i_ds++)
{
if(xpoid_none != (ds_list->list)[i_ds].page_size)
{
medium = (ds_list->list)[i_ds].page_size;
break;
}
}
}
}
XpOidMediumSSDelete(local_msss);
}
return medium;
}
/*
* XpGetMediumMillimeters returns into the supplied float pointers the
* width and height in millimeters of the passed page size identifier.
*/
void
XpGetMediumMillimeters(
XpOid page_size,
float *width, /* return */
float *height) /* return */
{
int i;
*width = *height = 0;
for(i = 0; i < XpNumber(PageDimensions); i++)
{
if(page_size == PageDimensions[i].page_size)
{
*width = PageDimensions[i].width;
*height = PageDimensions[i].height;
return;
}
}
}
/*
* Converts a millimeter specification into pixels given a resolution in
* DPI.
*/
static float
MmToPixels(float mm, int resolution)
{
float f;
f = mm * resolution;
f /= 25.4;
return f;
}
/*
* XpGetMediumDimensions returns into the supplied short pointers the
* width and height in pixels of the medium associated with the specified
* print context. It obtains the page size associated with the current
* medium by calling XpGetPageSize. It passes XpGetMediumMillimeters the
* page size, and converts the returned millimeter dimensions into pixels
* using the resolution returned by XpGetResolution.
*
* Note: This routine assumes the values found in the passed context's
* attributes pools have been validated.
*/
void
XpGetMediumDimensions(
XpContextPtr pContext,
unsigned short *width, /* return */
unsigned short *height) /* return */
{
XpOid page_size;
XpOid tray;
XpOid orientation;
int resolution;
float w_mm, h_mm;
page_size = XpGetPageSize(pContext, &tray, (XpOidMediumSS*)NULL);
if(page_size == xpoid_none)
{
/*
* fail-safe: if the pools have been validated, this defaulting logic
* isn't needed.
*/
page_size = xpoid_val_medium_size_na_letter;
}
XpGetMediumMillimeters(page_size, &w_mm, &h_mm);
resolution = XpGetResolution(pContext);
orientation = XpGetContentOrientation(pContext);
switch(orientation)
{
case xpoid_val_content_orientation_landscape:
case xpoid_val_content_orientation_reverse_landscape:
/*
* transpose width and height
*/
*height = MmToPixels(w_mm, resolution);
*width = MmToPixels(h_mm, resolution);
break;
default:
*width = MmToPixels(w_mm, resolution);
*height = MmToPixels(h_mm, resolution);
break;
}
}
/*
* XRectangleFromXpOidArea converts an XpOidArea area specification
* into an XRectangle. The passed resolution is used to convert from
* millimeters (XpOidArea) into pixels (XRectangle).
*/
static void
XRectangleFromXpOidArea(
xRectangle *pRect,
const XpOidArea* repro,
int resolution,
XpOid orientation)
{
switch(orientation)
{
case xpoid_val_content_orientation_landscape:
case xpoid_val_content_orientation_reverse_landscape:
/*
* transpose x and y, width and height
*/
pRect->y = MmToPixels(repro->minimum_x, resolution);
pRect->x = MmToPixels(repro->minimum_y, resolution);
pRect->height =
MmToPixels(repro->maximum_x - repro->minimum_x, resolution);
pRect->width =
MmToPixels(repro->maximum_y - repro->minimum_y, resolution);
break;
default:
pRect->x = MmToPixels(repro->minimum_x, resolution);
pRect->y = MmToPixels(repro->minimum_y, resolution);
pRect->width =
MmToPixels(repro->maximum_x - repro->minimum_x, resolution);
pRect->height =
MmToPixels(repro->maximum_y - repro->minimum_y, resolution);
break;
}
}
/*
* XpGetReproductionArea queries the current pool attribute values in
* order to determine the reproduction area for the currently selected
* medium.
*
* First the current page size (equivalent to current medium) and tray
* (if specified) is retrieved via XpGetPageSize. The value of the
* medium-source-sizes-supported attribute is interrogated until a matching
* entry for the current page size and tray is found. The reproduction
* area defined for the current entry is converted into an XRectangle
* using XRectangleFromXpOidArea and returned to the caller.
*
* Note: This routine assumes the values found in the passed context's
* attributes pools have been validated.
*/
void
XpGetReproductionArea(XpContextPtr pContext,
xRectangle *pRect)
{
XpOid page_size;
XpOid tray;
XpOidMediumSS* msss;
int i_mss, i_ds;
XpOidMediumDiscreteSizeList* ds_list;
XpOidArea* repro;
BOOL done;
int resolution;
XpOid orientation;
/*
* find the appropriate assured reproduction area for the current
* tray and page size in the medium-source-sizes-supported attribute.
*/
msss = XpGetMediumSSAttr(pContext, XPPrinterAttr,
xpoid_att_medium_source_sizes_supported,
(const XpOidList*)NULL,
(const XpOidList*)NULL);
page_size = XpGetPageSize(pContext, &tray, msss);
resolution = XpGetResolution(pContext);
orientation = XpGetContentOrientation(pContext);
memset(pRect, 0, sizeof(xRectangle));
if(xpoid_none == tray)
{
/*
* no tray specified; use 1st matching page size
*/
for(i_mss = 0, done = xFalse;
i_mss < XpOidMediumSSCount(msss) && !done;
i_mss++)
{
if(XpOidMediumSS_DISCRETE == (msss->mss)[i_mss].mstag
&&
xpoid_none != (msss->mss)[i_mss].input_tray)
{
ds_list = (msss->mss)[i_mss].ms.discrete;
for(i_ds = 0; i_ds < ds_list->count; i_ds++)
{
if(page_size == (ds_list->list)[i_ds].page_size)
{
repro =
&(ds_list->list)[i_ds].assured_reproduction_area;
XRectangleFromXpOidArea(pRect, repro,
resolution, orientation);
done = xTrue;
break;
}
}
}
}
}
else
{
/*
* tray && page size specified; find matching entry
*/
for(i_mss = 0, done = xFalse;
i_mss < XpOidMediumSSCount(msss) && !done;
i_mss++)
{
if(XpOidMediumSS_DISCRETE == (msss->mss)[i_mss].mstag
&&
xpoid_none != (msss->mss)[i_mss].input_tray
&&
(tray == (msss->mss)[i_mss].input_tray
||
xpoid_unspecified == (msss->mss)[i_mss].input_tray)
)
{
ds_list = (msss->mss)[i_mss].ms.discrete;
for(i_ds = 0; i_ds < ds_list->count; i_ds++)
{
if(page_size == (ds_list->list)[i_ds].page_size)
{
repro =
&(ds_list->list)[i_ds].assured_reproduction_area;
XRectangleFromXpOidArea(pRect, repro,
resolution, orientation);
if(xpoid_unspecified != (msss->mss)[i_mss].input_tray)
{
/*
* exact match on tray takes precendence over
* unspecified tray entry in m-s-s-s
*/
done = xTrue;
}
break;
}
}
}
}
}
XpOidMediumSSDelete(msss);
}
/*
* XpGetMaxWidthHeightRes returns into the supplied width and height
* unsigned short pointers the dimensions in millimeters of the largest
* supported media for a specific printer. It looks at the
* medium-source-sizes-supported attribute (if it exists) to determine
* the list of possible media, and calls XpGetMediumMillimeters to get the
* dimensions for each medium. If the m-s-s-s attribute is not defined,
* then the dimensions for the na-letter medium is returned.
*
* This function also returns the largest resolution in DPI defined in
* printer-resolutions-supported. If printer-resolutions-supported is not
* specified, the default is obtained from the passed XpValidatePoolsRec.
*
* The passed XpValidatePoolsRec is also used to determine valid values
* when parsing attribute values.
*/
void
XpGetMaxWidthHeightRes(
const char *printer_name,
const XpValidatePoolsRec* vpr,
float *width,
float *height,
int* resolution)
{
const char* value;
const char* attr_str;
XpOidMediumSS* pool_msss;
const XpOidMediumSS* msss;
int i_mss, i_ds;
XpOidMediumDiscreteSizeList* ds_list;
float w, h;
XpOidCardList* pool_resolutions_supported;
const XpOidCardList* resolutions_supported;
int i;
int res;
/*
* get the max medium width and height
*/
attr_str = XpOidString(xpoid_att_medium_source_sizes_supported);
value = XpGetPrinterAttribute(printer_name, attr_str);
pool_msss = XpOidMediumSSNew(value,
vpr->valid_input_trays,
vpr->valid_medium_sizes);
if(0 == XpOidMediumSSCount(pool_msss))
msss = XpGetDefaultMediumSS();
else
msss = pool_msss;
*width = *height = 0;
for(i_mss = 0; i_mss < XpOidMediumSSCount(msss); i_mss++)
{
if(XpOidMediumSS_DISCRETE == (msss->mss)[i_mss].mstag
&&
xpoid_none != (msss->mss)[i_mss].input_tray)
{
ds_list = (msss->mss)[i_mss].ms.discrete;
for(i_ds = 0; i_ds < ds_list->count; i_ds++)
{
if(xpoid_none != (ds_list->list)[i_ds].page_size)
{
XpGetMediumMillimeters((ds_list->list)[i_ds].page_size,
&w, &h);
if(w > *width) *width = w;
if(h > *height) *height = h;
}
}
}
}
XpOidMediumSSDelete(pool_msss);
/*
* get the maximum resolution
*/
attr_str = XpOidString(xpoid_att_printer_resolutions_supported);
value = XpGetPrinterAttribute(printer_name, attr_str);
pool_resolutions_supported =
XpOidCardListNew(value, vpr->valid_printer_resolutions_supported);
if(0 == XpOidCardListCount(pool_resolutions_supported))
resolutions_supported = vpr->default_printer_resolutions_supported;
else
resolutions_supported = pool_resolutions_supported;
*resolution = 0;
for(i = 0; i < XpOidCardListCount(resolutions_supported); i++)
{
res = XpOidCardListGetCard(resolutions_supported, i);
if(res > *resolution) *resolution = res;
}
XpOidCardListDelete(pool_resolutions_supported);
}
FontResolutionPtr
XpGetClientResolutions(client, num)
ClientPtr client;
int *num;
{
static struct _FontResolution res;
int resolution = XpGetResolution(XpContextOfClient(client));
res.x_resolution = resolution;
res.y_resolution = resolution;
res.point_size = 120;
*num = 1;
return &res;
}
void XpSetFontResFunc(client)
ClientPtr client;
{
client->fontResFunc = XpGetClientResolutions;
}
void XpUnsetFontResFunc(client)
ClientPtr client;
{
client->fontResFunc = NULL;
}
|