2 /* Copyright (C) 2002 Olivier Chapuis */
7 /* ---------------------------- included header files ---------------------- */
11 #include <X11/Xlocale.h>
12 #include <X11/Xutil.h>
19 /* FlocaleCharset.h and Ficonv.h should not be included */
22 /* ---------------------------- global definitions ------------------------- */
24 #define FWS_HAVE_LENGTH (1)
26 #define FLC_ENCODING_TYPE_NONE 0
27 #define FLC_ENCODING_TYPE_FONT 1
28 #define FLC_ENCODING_TYPE_UTF_8 2
29 #define FLC_ENCODING_TYPE_USC_2 3
30 #define FLC_ENCODING_TYPE_USC_4 4
31 #define FLC_ENCODING_TYPE_UTF_16 5
33 #define FLC_FFT_ENCODING_ISO8859_1 "ISO8859-1"
34 #define FLC_FFT_ENCODING_ISO10646_1 "ISO10646-1"
36 #define FLOCALE_FALLBACK_XCHARSET "ISO8859-1"
37 #define FLOCALE_UTF8_XCHARSET "ISO10646-1"
38 #define FLOCALE_ICONV_CONVERSION_MAX_NUMBER_OF_WARNING 10
40 #define FLC_INDEX_ICONV_CHARSET_NOT_FOUND -1
41 #define FLC_INDEX_ICONV_CHARSET_NOT_INITIALIZED -2
43 #define FLOCALE_DEBUG_SETLOCALE 0
44 #define FLOCALE_DEBUG_CHARSET 0
45 #define FLOCALE_DEBUG_ICONV 0
47 /* ---------------------------- global macros ------------------------------ */
49 #define IS_TEXT_DRAWN_VERTICALLY(x) \
50 ((x) == TEXT_ROTATED_90 || (x) == TEXT_ROTATED_270)
52 #define FLC_GET_X_CHARSET(fc) ((fc) != NULL)? (fc)->x:NULL
53 #define FLC_SET_ICONV_INDEX(fc, i) (fc)->iconv_index = i
54 #define FLC_GET_LOCALE_CHARSET(fc, i) (fc)->locale[i]
55 #define FLC_GET_ICONV_CHARSET(fc) \
56 ((fc) != NULL && (fc)->iconv_index >= 0)? (fc)->locale[(fc)->iconv_index]:NULL
57 #define FLC_DO_ICONV_CHARSET_INITIALIZED(fc) \
58 ((fc) != NULL && (fc)->iconv_index != FLC_INDEX_ICONV_CHARSET_NOT_INITIALIZED)
59 #define FLC_HAVE_ICONV_CHARSET(fc) ((fc) != NULL && (fc)->iconv_index >= 0)
60 #define FLC_GET_BIDI_CHARSET(fc) ((fc) != NULL)? (fc)->bidi : NULL
61 #define FLC_ENCODING_TYPE_IS_UTF_8(fc) \
62 ((fc) != NULL && (fc)->encoding_type == FLC_ENCODING_TYPE_UTF_8)
63 #define FLC_ENCODING_TYPE_IS_USC_2(fc) \
64 ((fc) != NULL && (fc)->encoding_type == FLC_ENCODING_TYPE_USC_2)
65 #define FLC_ENCODING_TYPE_IS_USC_4(fc) \
66 ((fc) != NULL && (fc)->encoding_type == FLC_ENCODING_TYPE_USC_4)
68 #define FLC_DEBUG_GET_X_CHARSET(fc) \
69 ((fc) == NULL || (fc)->x == NULL)? "None":(fc)->x
70 #define FLC_DEBUG_GET_ICONV_CHARSET(fc) \
71 ((fc) != NULL && (fc)->iconv_index >= 0)? (fc)->locale[(fc)->iconv_index]:"None"
72 #define FLC_DEBUG_GET_BIDI_CHARSET(fc) \
73 ((fc) == NULL || (fc)->bidi == NULL)? "None":(fc)->bidi
75 #define FLF_MULTIDIR_HAS_UPPER(flf) \
76 (((flf)->flags.shadow_dir & MULTI_DIR_NW) || \
77 ((flf)->flags.shadow_dir & MULTI_DIR_N) || \
78 ((flf)->flags.shadow_dir & MULTI_DIR_NE))
79 #define FLF_MULTIDIR_HAS_BOTTOM(flf) \
80 (((flf)->flags.shadow_dir & MULTI_DIR_SW) || \
81 ((flf)->flags.shadow_dir & MULTI_DIR_S) || \
82 ((flf)->flags.shadow_dir & MULTI_DIR_SE))
83 #define FLF_MULTIDIR_HAS_LEFT(flf) \
84 (((flf)->flags.shadow_dir & MULTI_DIR_SW) || \
85 ((flf)->flags.shadow_dir & MULTI_DIR_W) || \
86 ((flf)->flags.shadow_dir & MULTI_DIR_NW))
87 #define FLF_MULTIDIR_HAS_RIGHT(flf) \
88 (((flf)->flags.shadow_dir & MULTI_DIR_SE) || \
89 ((flf)->flags.shadow_dir & MULTI_DIR_E) || \
90 ((flf)->flags.shadow_dir & MULTI_DIR_NE))
92 #define FLF_SHADOW_FULL_SIZE(flf) ((flf)->shadow_size + (flf)->shadow_offset)
93 #define FLF_SHADOW_HEIGHT(flf) \
94 (FLF_SHADOW_FULL_SIZE((flf)) * \
95 (FLF_MULTIDIR_HAS_UPPER((flf))+FLF_MULTIDIR_HAS_BOTTOM((flf))))
96 #define FLF_SHADOW_WIDTH(flf) \
97 (FLF_SHADOW_FULL_SIZE((flf)) * \
98 (FLF_MULTIDIR_HAS_LEFT((flf))+FLF_MULTIDIR_HAS_RIGHT((flf))))
99 #define FLF_SHADOW_ASCENT(flf) \
100 (FLF_SHADOW_FULL_SIZE((flf)) * FLF_MULTIDIR_HAS_UPPER((flf)))
101 #define FLF_SHADOW_DESCENT(flf) \
102 (FLF_SHADOW_FULL_SIZE((flf)) * FLF_MULTIDIR_HAS_BOTTOM((flf)))
104 #define FLF_SHADOW_LEFT_SIZE(flf) \
105 (FLF_SHADOW_FULL_SIZE((flf)) * FLF_MULTIDIR_HAS_LEFT((flf)))
106 #define FLF_SHADOW_RIGHT_SIZE(flf) \
107 (FLF_SHADOW_FULL_SIZE((flf)) * FLF_MULTIDIR_HAS_RIGHT((flf)))
108 #define FLF_SHADOW_UPPER_SIZE(flf) \
109 (FLF_SHADOW_FULL_SIZE((flf)) * FLF_MULTIDIR_HAS_UPPER((flf)))
110 #define FLF_SHADOW_BOTTOM_SIZE(flf) \
111 (FLF_SHADOW_FULL_SIZE((flf)) * FLF_MULTIDIR_HAS_BOTTOM((flf)))
113 #define FLF_FONT_HAS_ALPHA(flf,cset) \
114 ((flf && flf->fftf.fftfont != None) || \
115 (0 && cset >= 0 && Colorset[cset].fg_alpha_percent < 100))
116 /* ---------------------------- type definitions --------------------------- */
118 typedef struct FlocaleCharset
120 char *x
; /* X font charset */
121 char **locale
; /* list of possible charset names */
122 int iconv_index
; /* defines the iconv charset name */
123 char *bidi
; /* if not null a fribidi charset */
124 short encoding_type
; /* encoding: font, utf8 or usc2 */
127 typedef struct _FlocaleFont
129 struct _FlocaleFont
*next
;
132 XFontStruct
*font
; /* font structure */
133 XFontSet fontset
; /* font set */
134 FftFontType fftf
; /* fvwm xft font */
135 FlocaleCharset
*fc
; /* fvwm charset of the font */
136 FlocaleCharset
*str_fc
; /* fvwm charset of the strings to be displayed */
137 int height
; /* height of the font: ascent + descent */
145 unsigned shadow_dir
: (DIR_ALL_MASK
+ 1);
146 unsigned must_free_fc
: 1;
147 /* is_mb are used only with a XFontStruct font, for XFontSet
148 * everything is done in the good way automatically and this
149 * parameters is not needed */
150 unsigned is_mb
: 1; /* if true the font is a 2 bytes font */
157 char *e_str
; /* tmp */
158 XChar2b
*str2b
; /* tmp */
160 colorset_t
*colorset
;
168 unsigned text_rotation
: 2;
169 unsigned has_colorset
: 1;
170 unsigned has_clip_region
: 1;
187 multi_direction_t direction
;
193 unsigned sdir
: (DIR_ALL_MASK
+ 1);
197 /* ---------------------------- exported variables (globals) --------------- */
199 /* ---------------------------- interface functions ------------------------ */
202 * i18n X initialization
203 * category: the usual category LC_CTYPE, LC_CTIME, ...
204 * modifier: "" or NULL if NULL XSetLocaleModifiers is not called
205 * module: the name of the fvwm module that call the function for reporting
207 * The locale and the modifiers is sotred in Flocale and Fmodifiers.
208 * Flocale is set to NULL if the locale is not supported by the Xlib.
209 * In this case the Flocale* functions below does not use the Xmb* functions
211 * The function should be called as FlocaleInit(LC_CTYPE, "", "", "myname");
214 int category
, const char *local
, const char *modifier
,
222 * load a FlocaleFont (create it or load it from a cache)
223 * fontname: a ";" sperated list of "," separated list of XFLD font names or
224 * either "xft:" followed by a Xft font name. Examples:
225 * "xft:Verdana:Bold:pixelsize=14:rgba=rgb"
226 * "xft:Verdana:size=12;-adobe-courier-medium-r-normal--14-*,fixed"
227 * module: name of the fvwm module for errors msg
228 * If fontname is NULL the "default font" is loaded (2,3,4).
229 * The following logic is used:
230 * 0) If fontname has been has been already loaded the cache is used
231 * 1) We try to load each element "fn" of the ";" seprated list until success
233 * a - if fn begin with "xft:", then if FftSupport fn is loaded as an xft
234 * font; if !FftSupport fn is skipped (ignored)
235 * b - If the locale is supported fn is loaded using XCreateFontSet. If this
236 * fail fallback into 1-c)
237 * c - If the locale is not supported or 1-b fail fn is loaded using
238 * XLoadQueryFont (the first loadable font in the fn "," separated list
240 * 2) If 0) and 1) fail:
241 * - try to load MB_FALLBACK_FONT with XCreateFontSet
242 * - If this fail try to load FALLBACK_FONT with XLoadQueryFont
243 * 3) If everything fail the function return NULL.
245 * If font loading succed. Only one of the font, fontset, fftfont member of the
246 * FlocaleFont structure is not NULL/None. The caller should use this to
247 * set appropriately the gc member of the FlocaleWinString struct (the fid
248 * gc member should be set only if font is not NULL).
251 FlocaleFont
*FlocaleLoadFont(Display
*dpy
, char *fontname
, char *module
);
254 * unload the flf FlocaleFont
256 void FlocaleUnloadFont(Display
*dpy
, FlocaleFont
*flf
);
263 * Draw the text specified in fstring->str using fstring->gc as GC on the
264 * fstring->win window at position fstring->{x,y} using the ff FlocaleFont.
265 * If flags & FWS_HAVE_LENGTH, the fstring->len first characters of the
266 * string is drawn. If !(flags & FWS_HAVE_LENGTH), the function draw the
267 * the all string (fstring->len is ignored). Note that if ff->font is NULL
268 * the gc should not conatins a GCFont, as if ff->font != NULL the GCFont
269 * value should be ff->font->fid
271 void FlocaleDrawString(
272 Display
*dpy
, FlocaleFont
*ff
, FlocaleWinString
*fstring
,
273 unsigned long flags
);
276 * Underline a character in a string (pete@tecc.co.uk) at coffest position
278 void FlocaleDrawUnderline(
279 Display
*dpy
, FlocaleFont
*flf
, FlocaleWinString
*fws
, int coffset
);
282 * Get the position for shadow text
284 void FlocaleInitGstpArgs(
285 flocale_gstp_args
*args
, FlocaleFont
*flf
, FlocaleWinString
*fws
,
286 int start_x
, int start_y
);
288 Bool
FlocaleGetShadowTextPosition(
289 int *x
, int *y
, flocale_gstp_args
*args
);
292 * Call XmbTextEscapement(ff->fontset, str, sl) if ff->fontset is not None.
293 * Call XTextWith(ff->font, str, sl) if ff->font is not NULL.
294 * If sl is negative, the string is considered to be a vertival string and
295 * the function returns the height of the text.
297 int FlocaleTextWidth(FlocaleFont
*ff
, char *str
, int sl
);
300 * "y" (or "x" position if rotated and Xft font) of the text relatively to 0
302 int FlocaleGetMinOffset(FlocaleFont
*flf
, rotation_t rotation
);
305 * Allocate memory for a FlocaleWinString intialized to 0
307 void FlocaleAllocateWinString(FlocaleWinString
**pfws
);
314 * return the window or icon name of a window w
315 * func: XGetWMName or XGetWMIconName
317 * w: the window for which we want the (icon) name
319 * ret_name: the icon or the window name of the window
321 void FlocaleGetNameProperty(
322 Status (func
)(Display
*, Window
, XTextProperty
*), Display
*dpy
,
323 Window w
, FlocaleNameString
*ret_name
);
326 * Free the name property allocated with FlocaleGetNameProperty
328 void FlocaleFreeNameProperty(
329 FlocaleNameString
*ptext
);
332 * Simple warper to XmbTextListToTextProperty (FlocaleMultibyteSupport and the
333 * locale is supported by the xlib) or XStringListToTextProperty
335 Bool
FlocaleTextListToTextProperty(
336 Display
*dpy
, char **list
, int count
, XICCEncodingStyle style
,
337 XTextProperty
*text_prop_return
);
342 void FlocalePrintLocaleInfo(Display
*dpy
, int verbose
);
348 /* return number of bytes of character at current position
349 (pointed to by str) */
350 int FlocaleStringNumberOfBytes(FlocaleFont
*flf
, const char *str
);
352 /* given a string, font specifying its locale and a byte offset gives
354 int FlocaleStringByteToCharOffset(FlocaleFont
*flf
, const char *str
,
357 /* like above but reversed, ie. return byte offset corresponding to given
359 int FlocaleStringCharToByteOffset(FlocaleFont
*flf
, const char *str
,
362 /* return length of string in characters */
363 int FlocaleStringCharLength(FlocaleFont
*flf
, const char *str
);
366 #endif /* FLOCALE_H */