File: check1.c

package info (click to toggle)
libemf 1.0.13-8
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,944 kB
  • sloc: ansic: 14,467; cpp: 5,857; makefile: 47; sh: 3
file content (156 lines) | stat: -rw-r--r-- 5,272 bytes parent folder | download | duplicates (3)
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
/*
 * Checkout program for the EMF library
 * Copyright (C) 2002, 2003 lignum Computing, Inc. <dallenbarnett@users.sourceforge.net>
 * $Id: check1.c 70 2015-11-21 21:14:35Z dallenbarnett $
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 */

#include <libEMF/emf.h>

static XFORM xform = { 2., 0., 0., 2., -3., -4. };

static POINT plarray[4] = { { -4, -3 }, { -2, -1 }, { 0, 1 }, { 2, 3 } };
static POINT plarrayl[4] = { { -400000, -300000 }, { -200000, -100000 },
			     { 0, 100000 }, { 200000, 300000 } };
static POINT pltoarray[4] = { { -10, -20 }, { -30, -40 }, { 50, 61 }, { 72, 83 } };
static POINT pltoarrayl[4] = { { -1000000, -2000000 }, { -3000000, -4000000 },
			       { 5000000, 6100000 }, { 7200000, 8300000 } };
static POINT pgarray[4] = {
  { -400, -300 }, { -200, -100 }, { 0, 100 }, { 200, 300 }
};
static POINT pgarrayl[4] = {
  { -40000000, -30000000 }, { -20000000, -10000000 },
  { 0, 10000000 }, { 20000000, 30000000 }
};
static INT advances[7] = { 11, 22, 33, 44, 55, 66, 77 };
static POINT plplarray[7] = { { -101, -201 }, { -301, -401 }, { -501, -601 },
			      { 101, 201 }, { 301, 401 }, { 501, 601 }, { 701, 801 } };
static POINT plplarrayl[7] = { { -10100000, -20100000 }, { -30100000, -40100000 },
			       { -50100000, -60100000 },
			       { 10100000, 20100000 }, { 30100000, 40100000 },
			       { 50100000, 60100000 }, { 70100000, 80100000 } };
static INT plplsizes[2] = { 3, 4 };
static LOGPEN lpen = { PS_SOLID, {20,20}, RGB(0,0xff,0xff) };
static LOGBRUSH lbrush = { BS_HATCHED, RGB(0x0,0x0,0xff), HS_DIAGCROSS };

int main ( int argc, char* argv[] )
{
  (void)argc;
  (void)argv;

  HWND desktop = GetDesktopWindow();
  HDC dc = GetDC( desktop );

  RECT size = { 0, 0, 10000, 20000 }; /* 10cm x 20cm */
  PCSTR filename = "check1.emf";
  PCSTR description = "Test metafile created\0with libEMF\0";

  HENHMETAFILE mfh;
  HDC metaDC = CreateEnhMetaFile( dc, filename, &size, description );

  HPEN pen;
  HBRUSH brush;
  HFONT font;

  FLOAT old_miter_limit;

  SetViewportOrgEx( metaDC, 123, 456, 0 );
  SetViewportExtEx( metaDC, 789, 1011, 0 );
  ScaleViewportExtEx( metaDC, 1, 2, 1, 2, 0 );

  SetWindowOrgEx( metaDC, 124, 248, 0 );
  SetWindowExtEx( metaDC, 481, 812, 0 );
  ScaleWindowExtEx( metaDC, 1, 2, 1, 2, 0 );

  ModifyWorldTransform( metaDC, &xform, MWT_IDENTITY );
  SetWorldTransform( metaDC, &xform );

  SetTextColor( metaDC, RGB(0x12,0x34,0x56) );
  SetTextAlign( metaDC, TA_CENTER+TA_BASELINE );
  SetBkMode( metaDC, TRANSPARENT );
  SetBkColor( metaDC, RGB(0x78,0x9a,0xbc) );
  SetPolyFillMode( metaDC, WINDING );
  SetMapMode( metaDC, MM_ANISOTROPIC );

  SelectObject( metaDC, GetStockObject( WHITE_BRUSH ) );

  MoveToEx( metaDC, 123, 456, 0 );
  LineTo( metaDC, 789, 1011 );

  Arc( metaDC, 12, 23, 34, 45, 56, 67, 78, 89 );
  ArcTo( metaDC, 12, 23, 34, 45, 56, 67, 78, 89 );

  Rectangle( metaDC, 98, 76, 54, 32 );
  Ellipse( metaDC, 32, 54, 76, 98 );

  SetMiterLimit( metaDC, 20.f, &old_miter_limit );
  Polyline( metaDC, plarray, 4 );
  Polyline( metaDC, plarrayl, 4 );
  PolylineTo( metaDC, pltoarray, 4 );
  PolylineTo( metaDC, pltoarrayl, 4 );
  PolyBezier( metaDC, plarray, 4 );
  PolyBezier( metaDC, plarrayl, 4 );
  PolyBezierTo( metaDC, pltoarray, 4 );
  PolyBezierTo( metaDC, pltoarrayl, 4 );
  Polygon( metaDC, pgarray, 4 );
  Polygon( metaDC, pgarrayl, 4 );
  PolyPolygon( metaDC, plplarray, plplsizes, 2 );
  PolyPolygon( metaDC, plplarrayl, plplsizes, 2 );

  TextOut( metaDC, 50, 75, "A larger font, e?", 17 );
  ExtTextOut( metaDC, 100, 200, ETO_GRAYED|ETO_CLIPPED, 0, "And now", 7, advances );

  pen = CreatePenIndirect( &lpen );
  SelectObject( metaDC, pen );
  SelectObject( metaDC, GetStockObject( GRAY_BRUSH ) );
  DeleteObject( GetStockObject( GRAY_BRUSH ) );

  brush = CreateBrushIndirect( &lbrush );
  SelectObject( metaDC, brush );

  font = CreateFont( -11, 0, 0, 0, FW_BOLD, 0, 0, 0, ANSI_CHARSET,
		     OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY,
		     DEFAULT_PITCH | FF_DONTCARE, "Helvetica" );
  SelectObject( metaDC, font );
  DeleteObject( font );
  DeleteObject( brush );
  DeleteObject( pen );

  BeginPath( metaDC );
  EndPath( metaDC );
  CloseFigure( metaDC );

  FillPath( metaDC );
  StrokePath( metaDC );
  StrokeAndFillPath( metaDC );

  SetPixel( metaDC, 123, 456, RGB(0x24,0x68,0xac) );

  SaveDC( metaDC );
  SetMetaRgn( metaDC );
  RestoreDC( metaDC, 1 );

  pen = ExtCreatePen( PS_SOLID, 1, &lbrush, 0, 0 );
  SelectObject( metaDC, pen );
  DeleteObject( pen );

  mfh = CloseEnhMetaFile( metaDC );
  DeleteEnhMetaFile( mfh );
  DeleteDC( metaDC );

  return 0;
}