30
30
* Version Creation Date: 1/1/91
34
34
* File Description:
35
35
* Vibrant drawing functions.
38
38
* --------------------------------------------------------------------------
39
* $Log: ncbidraw.c,v $
40
* Revision 6.40 2006/09/14 19:18:28 ivanov
41
* Rollback last changes. All missed defines added to corelib/ncbiwin.h.
43
* Revision 6.39 2006/09/14 18:05:45 ivanov
44
* Fixed compilation errors on MS Windows
46
* Revision 6.38 2006/09/14 14:45:38 kans
47
* changes for 64-bit Windows (GC) plus a few CodeWarrior complaints (JK)
49
* Revision 6.37 2004/04/14 19:15:50 sinyakov
50
* WIN_MSWIN: support X-Windows-like -bg color command line option
52
* Revision 6.36 2003/11/17 17:03:30 kans
53
* changed C++ style comments to C comments
55
* Revision 6.35 2003/03/19 21:13:22 kans
56
* protect UNIX version of ScrollRect
58
* Revision 6.34 2002/06/13 16:15:12 kans
59
* fix includes for OS_UNIX_DARWIN with WIN_MAC (EN) - still bug in vibutils.c file dialog
61
* Revision 6.33 2002/03/28 13:35:48 kans
62
* only include MoreCarbonAccessors.h if not OS_UNIX_DARWIN
64
* Revision 6.32 2002/03/06 20:15:14 northup
65
* under X11 cache colors from XAllocColor using a hash table. (EN)
67
* Revision 6.31 2002/02/04 19:04:51 kans
68
* pass fsp.size to LoadFontData for systemFont on Mac - now label width calculated correctly
70
* Revision 6.30 2002/02/04 18:49:15 kans
71
* fsp.size = GetDefFontSize () for systemFont on Mac - Mac OS X uses Lucida Grande 13
73
* Revision 6.29 2001/08/29 21:14:10 juran
74
* Move Carbon forward-compatibility to MoreCarbonAccessors.h.
75
* Call InvalRgn instead of InvalWindowRegion.
77
* Revision 6.28 2001/04/05 19:45:50 juran
80
* Revision 6.27 2000/02/07 20:17:35 lewisg
81
* minor bug fixes, use gui font for win32
83
* Revision 6.26 2000/01/24 16:11:13 lewisg
84
* speed up seqid comparison in color manager, make fast windows version of SetColor()
86
* Revision 6.25 2000/01/13 23:37:13 beloslyu
87
* changes because of port to HP-UX 11.0
89
* Revision 6.24 1999/12/21 18:04:23 kans
90
* removed MPW/THINKC conditional code, starting upgrade to Carbon compatibility - Churchill
92
* Revision 6.23 1999/10/20 23:08:10 vakatov
93
* + Nlm_SetCurrentGIF() -- to set Nlm_currentGIF directly.
94
* + Nlm_DestroyGIF() -- to destroy Nlm_currentGIF.
95
* Nlm_CreateGIF() and Nlm_SaveGIF() -- do not destroy Nlm_currentGIF.
97
* Revision 6.22 1999/10/04 18:44:02 vakatov
98
* [WIN_GIF] Nlm_SelectFont() -- fixed the way the font gets chosen
100
* Revision 6.21 1999/03/17 15:10:47 vakatov
101
* + Nlm_XLoadStandardFont() to find a "last-resort" font
103
* Revision 6.20 1998/08/12 14:52:26 vakatov
104
* [MSWIN] Nlm_DrawLine(): draw at least one point(fix to R6.8)
106
* Revision 6.19 1998/07/27 16:49:23 vakatov
107
* [WIN_X] AddNewFont(): try "-*-" in addition to "--" in font name spec.
109
* Revision 6.18 1998/07/24 21:43:14 vakatov
110
* [WIN_MSWIN] It looks like the metafile driver does not support
111
* extended userstyle pens, so use plain pens when writing to metafile
113
* Revision 6.17 1998/07/14 16:44:24 vakatov
114
* Added VibrantIsGUI() and <internal> Nlm_VibrantSetGUI()
116
* Revision 6.16 1998/07/01 22:07:16 vakatov
117
* s_AdjustRoundRect(): one-pixel fix
119
* Revision 6.15 1998/07/01 18:27:41 vakatov
120
* Use "const" qualifier somewhere
122
* Revision 6.14 1998/06/26 20:00:17 vakatov
123
* Added s_AdjustRoundRect() to adjust the rounding sizes in Nlm_*RoundRect()
125
* Revision 6.13 1998/06/25 18:36:29 vakatov
126
* [WIN_MSWIN] Minor 1-pixel adjustments to synchronize graphic primitives
128
* Revision 6.12 1998/06/12 16:40:12 kans
129
* fixed warnings detected by unix compiler
131
* Revision 6.11 1998/06/01 17:20:11 vakatov
132
* Added code to draw/fill 90-degree arc/pie (quadrants)
134
* Revision 6.10 1998/04/27 15:58:46 vakatov
135
* Implemented the drawing of rounded rectangles and ovals for GIF and X11
137
* Revision 6.9 1998/02/06 16:10:18 vakatov
138
* [WIN_X] SetUpDrawingTools(): fixed mem.leak(default font info)
140
* Revision 6.8 1998/02/05 20:07:08 vakatov
141
* [X11,MSWIN] Made DrawLine() always draw the last and the first point
142
* (to be in-sync with GIF and MAC)
144
* Revision 6.7 1997/12/12 21:08:20 kans
145
* a number of symbols changed in the latest CodeWarrior release, now using headers from Apple
147
* Revision 6.6 1997/11/26 21:29:59 vakatov
148
* Fixed errors and warnings issued by C and C++ (GNU and Sun) compilers
150
* Revision 6.5 1997/11/04 23:32:49 vakatov
151
* [WIN_X] #ULTRA_SPARC_X_SERVER_BUG -- workaround to set foreground color
152
* when the stippling is in effect -- see Nlm_XSetForeground() for details.
154
* Revision 6.4 1997/09/16 20:34:15 vakatov
155
* Added Nlm_FitStringWidth(); for now, it is implemented as native
156
* for [WIN_X] and generic for all other platforms.
157
* [WIN_X] Fixed bug in Nlm_AddNewFont() which disabled the font
160
* Revision 6.3 1997/09/11 00:00:38 vakatov
161
* [WIN_X] Nlm_EraseRect(): use XGetGCValues() to retrieve curr. fill style
163
* Revision 6.2 1997/09/10 18:23:35 vakatov
164
* [WIN_X] Nlm_EraseRect(): temp. switch fill style to FillSolid
166
* Revision 6.1 1997/09/09 23:53:36 vakatov
167
* [WIN_GIF] Nlm_Solid() -- reset the drawing pattern to solid
169
* Revision 5.22 1997/08/19 19:28:01 vakatov
170
* [WIN_GIF] Implemented Nlm_SelectPattern()-related features
172
* Revision 5.21 1997/07/23 19:42:17 vakatov
173
* Added Nlm_PaintStringEx function(text + position)
175
* Revision 5.20 1997/07/18 15:18:39 vakatov
176
* [!WIN_GIF] +Dummy Nlm_CreateGIF() and Nlm_SaveGIF(); /return FALSE/
178
* Revision 5.19 1997/07/10 21:49:21 vakatov
179
* [WIN_X] Now able to manage windows having different depths(and
180
* different visuals and GC).
182
* Revision 5.18 1997/06/18 19:46:27 vakatov
183
* [WIN_GIF] Do not use WIN_MAC/MSWIN/MOTIF-specific fields of the
184
* Nlm_FontRec struct.
186
* Revision 5.17 1997/06/09 18:54:33 vakatov
187
* [WIN_X] Nlm_XAllocColor() moved to "vibwndws.c"; Nlm_SetupColor()
188
* removed at all; use Nlm_VibrantDefaultColormap() and Nlm_XAllocColor()
189
* instead of 0 and XAllocColor() in most cases in order to use
190
* standard colormap rather than the default one.
191
* [ALL] Renamed("Local__" - prefixed) static coordination transformation funcs
192
* whose name conflicts with the global ones; +other code cleaning...
194
* Revision 5.16 1997/06/04 16:12:05 vakatov
195
* [WIN_MSWIN] PaintStringWin() has been removed again(see also R5.14)
197
* Revision 5.15 1997/06/04 00:05:12 kans
198
* support for Japanese by Tomo Koike of DDBJ
200
* Revision 5.14 1997/05/08 14:05:27 vakatov
201
* [WIN_MSWIN] PaintStringWin() is obsolete; replaced by MoveTo + PaintString
203
* Revision 5.13 1997/05/06 20:03:44 vakatov
204
* [WIN_GIF] Nlm_CreateGIF(): Boolean --> Nlm_Boolean (by J.Kuzio)
206
* Revision 5.12 1997/05/06 18:39:52 vakatov
207
* [WIN32] Nlm_SetPenDash() -- added #WIN_MSWIN cpp condition
209
* Revision 5.11 1997/04/22 17:32:28 vakatov
210
* [WIN_X] Nlm_DrawLine() -- correction of R5.6 for p1.[xy] > p2.[xy]
212
* Revision 5.10 1997/04/04 22:46:42 vakatov
213
* [WIN_MSWIN] Added static HFONT2Font() function; since now,
214
* "Nlm_systemFont" and "Nlm_programFont" are to be printed using
215
* the matching logical fonts obtained with HFONT2Font().
217
* Revision 5.9 1997/01/29 16:41:22 kans
220
* Revision 5.8 1996/12/11 22:29:19 vakatov
221
* [WIN_MSWIN] Nlm_ResetDrawingTools(): reset prevPenHDC to ensure
222
* proper brush pattern setting in some exotic cases
224
* Revision 5.7 1996/12/04 21:17:19 vakatov
225
* [WIN_X] Nlm_InvertRect(): use GXinvert both on b/w and color displays
227
* Revision 5.6 1996/12/04 16:12:08 vakatov
228
* [WIN_X] Made Nlm_DrawLine() always draw the last point; Nlm_MoveTo() now
229
* implemented via a call to Nlm_DrawLine().
231
* Revision 5.5 1996/11/21 22:26:22 vakatov
232
* [WIN_X] Made Nlm_LineTo() and Nlm_DrawLine() draw last point
234
* Revision 5.4 1996/11/21 18:50:59 vakatov
235
* [WIN_MOTIF] Rectangle and Polygon drawing sync. to other platforms
237
* Revision 5.3 1996/10/28 19:33:04 vakatov
238
* [WIN_MOTIF] Use Nlm_VibrantDefaultColormap() instead of the display
239
* default colormap everywhere in the color handling code.
241
* Revision 5.2 1996/10/01 18:17:37 vakatov
242
* [WIN_X] Added auxiliary static routine Nlm_XAllocColor() in order to
243
* provide a uniform way of the color allocating; on the color
244
* allocation error, it now returns "Black" pixel rather than "White".
246
* Revision 5.1 1996/09/30 19:54:08 vakatov
247
* [WIN_X, WIN_NT] Added Nlm_SetPenDash() to allow advanced line dashing
248
* [WIN_MSWIN] Nlm_PaintRect() -- synchronize it with Nlm_FrameRect(),
249
* Nlm_FrameOval(), etc. (left + 1, bottom + 1)
251
* Revision 5.0 1996/05/28 13:45:08 ostell
252
* Set to revision 5.0
254
* Revision 4.13 1996/05/10 21:12:33 vakatov
255
* Added UpdateColorTable() function to allow the user to read his color
256
* preferencies from an external config.-file in format:
257
* <index> <red> <green> <blue> [<name>];
258
* <name> is optional and it is only used in the WIN_MOTIF-based
259
* applications to get hardware-independent named colors, if possible.
261
* Revision 4.12 1996/04/15 19:31:56 tatiana
262
* add Boolean transparent to Nlm_CreateGIF()
264
* Revision 4.11 1996/02/01 22:42:01 smirnov
265
* AS: problem with symbols in clipboard is fixed
267
* Revision 4.10 1996/02/01 18:42:53 smirnov
268
* AS: fix bug: draw a small rectangle
270
* Revision 4.9 1996/01/31 18:47:32 smirnov
273
* Revision 4.8 1995/12/22 19:42:33 smirnov
274
* AS: Fixed bug in GIF version of DrawText()
276
* Revision 4.7 1995/11/27 15:47:55 kans
277
* fixed FrameArc (VL + JK)
279
* Revision 4.6 1995/11/27 15:13:41 kans
280
* corrections to font height, etc. functions (VL)
282
* Revision 4.4 1995/11/14 13:42:05 kans
283
* fixes to AddNewFont (VL)
285
* Revision 4.3 1995/11/07 15:47:22 smirnov
286
* add GIF generator (Alex Smirnov)
288
* Revision 4.2 1995/09/12 17:59:35 ostell
289
* fixes for MS windows text to metafile
291
* Revision 4.1 1995/09/12 00:39:10 ostell
292
* changes for text to appear in windows metafiles
294
* Revision 4.0 1995/07/26 13:51:04 ostell
295
* force revision to 4.0
297
* Revision 2.41 1995/07/14 17:48:26 kans
298
* new CopyPixmap (AS)
300
* Revision 2.40 1995/06/07 21:23:38 kans
301
* RecreateBrushes problem fixed (AS)
302
40
* ==========================================================================
2005
#ifdef WIN_MAC_ATSUI
2007
static Nlm_FontTool Nlm_FontToATSUStyle(Nlm_FonT f)
2009
Nlm_FontData fontData;
2010
Nlm_GetFontData (f, &fontData);
2011
return fontData.handle;
2015
static Nlm_FontTool Nlm_NewATSUStyle(Nlm_FontSpecPtr fsp)
2018
Nlm_FontTool style = NULL; /* type ATSUStyle */
2020
err = ATSUCreateStyle(&style);
2024
Boolean boldTag = FALSE;
2025
Boolean italicTag = FALSE;
2027
ATSUAttributeTag theTags[] = {kATSUFontTag, kATSUSizeTag, kATSUQDBoldfaceTag, kATSUQDItalicTag};
2028
ByteCount theSizes[] = {sizeof(ATSUFontID), sizeof(Fixed), sizeof(Boolean), sizeof(Boolean)};
2029
ATSUAttributeValuePtr theValues[] = {&fontID, &atsuSize, &boldTag, &italicTag};
2031
/* Get Font id from the name. */
2032
OSStatus err = ATSUFindFontFromName (
2033
fsp->name, strlen(fsp->name),
2034
kFontFullName, // kFontFamilyName,
2035
kFontMacintoshPlatform, // kFontUnicodePlatform for Unicode support.
2036
kFontNoScriptCode, kFontNoLanguageCode,
2039
if (err == kATSUInvalidFontErr)
2041
/* or can we do something more intelligent here? */
2045
if ((fsp->style & STYLE_BOLD) != 0) boldTag = TRUE;
2046
if ((fsp->style & STYLE_ITALIC) != 0) italicTag = TRUE;
2048
/* get the size ready */
2049
atsuSize = Long2Fix (fsp->size);
2051
/* put the attributes in to the style. */
2052
err = ATSUSetAttributes (
2054
sizeof(theTags)/sizeof(ATSUAttributeTag),
2071
2067
/* esl: main internal procedure to create fonts */
2072
2068
static Nlm_FonT Nlm_AddNewFont (Nlm_FontSpecPtr fsp, Nlm_Boolean residentp)
2074
2070
Nlm_FonT rsult;
2071
#if defined(WIN_MAC) && ! defined(WIN_MAC_ATSUI)
2076
2072
Nlm_Int2 num = 0;
2077
2073
Nlm_Int2 styl = 0;
2078
#else /* WIN_MSWIN | WIN_X */
2074
#else /* WIN_MSWIN | WIN_X | WIN_GIF | WIN_MAC_ATSUI */
2079
2075
Nlm_FontTool hdl = NULL;
5232
#ifdef WIN_MAC_QUARTZ
5234
static void pathForArc (CGContextRef context, CGRect r,
5235
int startAngle, int arcAngle)
5238
CGAffineTransform matrix;
5239
CGContextSaveGState(context);
5240
matrix = CGAffineTransformMake(r.size.width/2, 0,
5242
r.origin.x + r.size.width/2,
5243
r.origin.y + r.size.height/2);
5244
CGContextConcatCTM(context, matrix);
5246
start = (90 - startAngle - arcAngle) * M_PI / 180;
5247
end = (90 - startAngle) * M_PI / 180;
5249
start = (90 - startAngle) * M_PI / 180;
5250
end = (90 - startAngle - arcAngle) * M_PI / 180;
5252
CGContextAddArc (context, 0, 0, 1, start, end, false);
5253
CGContextRestoreGState(context);
5257
static void pathForArc (CGContextRef context, CGRect r,
5258
CGPoint startPt, CGPoint endPt)
5261
CGAffineTransform matrix, invMatrix;
5262
CGContextSaveGState(context);
5263
matrix = CGAffineTransformMake(r.size.width/2, 0,
5265
r.origin.x + r.size.width/2,
5266
r.origin.y + r.size.height/2);
5267
CGContextConcatCTM(context, matrix);
5269
invMatrix = CGAffineTransformInvert(matrix);
5270
startPt = CGPointApplyAffineTransform(startPt, invMatrix);
5271
endPt = CGPointApplyAffineTransform(endPt, invMatrix);
5272
start = atan2(startPt.y, startPt.x);
5273
end = atan2( endPt.y, endPt.x);
5276
CGContextAddArc (context, 0, 0, 1, start, end, 0);
5277
CGContextRestoreGState(context);
4776
5283
extern void Nlm_EraseArc(Nlm_RectPtr r, Nlm_PoinT start, Nlm_PoinT end)
4778
5285
Nlm_RectTool rtool;