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 FLC_TRANSLIT_NOT_SUPPORTED ((char*)-1)
45 #define FLOCALE_DEBUG_SETLOCALE 0
46 #define FLOCALE_DEBUG_CHARSET 0
47 #define FLOCALE_DEBUG_ICONV 0
49 /* ---------------------------- global macros ------------------------------ */
51 #define IS_TEXT_DRAWN_VERTICALLY(x) \
52 ((x) == TEXT_ROTATED_90 || (x) == TEXT_ROTATED_270)
54 #define FLC_GET_X_CHARSET(fc) ((fc) != NULL)? (fc)->x:NULL
55 #define FLC_SET_ICONV_INDEX(fc, i) (fc)->iconv_index = i
56 #define FLC_GET_LOCALE_CHARSET(fc, i) (fc)->locale[i]
57 #define FLC_GET_ICONV_CHARSET(fc) \
58 ((fc) != NULL && (fc)->iconv_index >= 0)? (fc)->locale[(fc)->iconv_index]:NULL
59 #define FLC_DO_ICONV_CHARSET_INITIALIZED(fc) \
60 ((fc) != NULL && (fc)->iconv_index != FLC_INDEX_ICONV_CHARSET_NOT_INITIALIZED)
61 #define FLC_HAVE_ICONV_CHARSET(fc) ((fc) != NULL && (fc)->iconv_index >= 0)
62 #define FLC_GET_BIDI_CHARSET(fc) ((fc) != NULL)? (fc)->bidi : NULL
63 #define FLC_ENCODING_TYPE_IS_UTF_8(fc) \
64 ((fc) != NULL && (fc)->encoding_type == FLC_ENCODING_TYPE_UTF_8)
65 #define FLC_ENCODING_TYPE_IS_USC_2(fc) \
66 ((fc) != NULL && (fc)->encoding_type == FLC_ENCODING_TYPE_USC_2)
67 #define FLC_ENCODING_TYPE_IS_USC_4(fc) \
68 ((fc) != NULL && (fc)->encoding_type == FLC_ENCODING_TYPE_USC_4)
70 #define FLC_DEBUG_GET_X_CHARSET(fc) \
71 ((fc) == NULL || (fc)->x == NULL)? "None":(fc)->x
72 #define FLC_DEBUG_GET_ICONV_CHARSET(fc) \
73 ((fc) != NULL && (fc)->iconv_index >= 0)? (fc)->locale[(fc)->iconv_index]:"None"
74 #define FLC_DEBUG_GET_BIDI_CHARSET(fc) \
75 ((fc) == NULL || (fc)->bidi == NULL)? "None":(fc)->bidi
77 #define FLC_IS_TRANSLIT_SUPPORTED(fc) \
78 ((fc) != NULL && (fc)->translit_csname != FLC_TRANSLIT_NOT_SUPPORTED \
79 && (fc)->translit_csname != NULL)
81 #define FLC_GET_ICONV_TRANSLIT_CHARSET(fc) \
82 ((fc) != NULL && (fc)->translit_csname != FLC_TRANSLIT_NOT_SUPPORTED)?\
83 (fc)->translit_csname : NULL
84 #define FLC_SET_ICONV_TRANSLIT_CHARSET(fs, csname) \
85 (fc)->translit_csname = csname
87 #define FLF_MULTIDIR_HAS_UPPER(flf) \
88 (((flf)->flags.shadow_dir & MULTI_DIR_NW) || \
89 ((flf)->flags.shadow_dir & MULTI_DIR_N) || \
90 ((flf)->flags.shadow_dir & MULTI_DIR_NE))
91 #define FLF_MULTIDIR_HAS_BOTTOM(flf) \
92 (((flf)->flags.shadow_dir & MULTI_DIR_SW) || \
93 ((flf)->flags.shadow_dir & MULTI_DIR_S) || \
94 ((flf)->flags.shadow_dir & MULTI_DIR_SE))
95 #define FLF_MULTIDIR_HAS_LEFT(flf) \
96 (((flf)->flags.shadow_dir & MULTI_DIR_SW) || \
97 ((flf)->flags.shadow_dir & MULTI_DIR_W) || \
98 ((flf)->flags.shadow_dir & MULTI_DIR_NW))
99 #define FLF_MULTIDIR_HAS_RIGHT(flf) \
100 (((flf)->flags.shadow_dir & MULTI_DIR_SE) || \
101 ((flf)->flags.shadow_dir & MULTI_DIR_E) || \
102 ((flf)->flags.shadow_dir & MULTI_DIR_NE))
104 #define FLF_SHADOW_FULL_SIZE(flf) ((flf)->shadow_size + (flf)->shadow_offset)
105 #define FLF_SHADOW_HEIGHT(flf) \
106 (FLF_SHADOW_FULL_SIZE((flf)) * \
107 (FLF_MULTIDIR_HAS_UPPER((flf))+FLF_MULTIDIR_HAS_BOTTOM((flf))))
108 #define FLF_SHADOW_WIDTH(flf) \
109 (FLF_SHADOW_FULL_SIZE((flf)) * \
110 (FLF_MULTIDIR_HAS_LEFT((flf))+FLF_MULTIDIR_HAS_RIGHT((flf))))
111 #define FLF_SHADOW_ASCENT(flf) \
112 (FLF_SHADOW_FULL_SIZE((flf)) * FLF_MULTIDIR_HAS_UPPER((flf)))
113 #define FLF_SHADOW_DESCENT(flf) \
114 (FLF_SHADOW_FULL_SIZE((flf)) * FLF_MULTIDIR_HAS_BOTTOM((flf)))
116 #define FLF_SHADOW_LEFT_SIZE(flf) \
117 (FLF_SHADOW_FULL_SIZE((flf)) * FLF_MULTIDIR_HAS_LEFT((flf)))
118 #define FLF_SHADOW_RIGHT_SIZE(flf) \
119 (FLF_SHADOW_FULL_SIZE((flf)) * FLF_MULTIDIR_HAS_RIGHT((flf)))
120 #define FLF_SHADOW_UPPER_SIZE(flf) \
121 (FLF_SHADOW_FULL_SIZE((flf)) * FLF_MULTIDIR_HAS_UPPER((flf)))
122 #define FLF_SHADOW_BOTTOM_SIZE(flf) \
123 (FLF_SHADOW_FULL_SIZE((flf)) * FLF_MULTIDIR_HAS_BOTTOM((flf)))
125 #define FLF_FONT_HAS_ALPHA(flf,cset) \
126 ((flf && flf->fftf.fftfont != None) || \
127 (0 && cset >= 0 && Colorset[cset].fg_alpha_percent < 100))
128 /* ---------------------------- type definitions --------------------------- */
130 typedef struct FlocaleCharset
132 char *x
; /* X font charset */
133 char **locale
; /* list of possible charset names */
134 int iconv_index
; /* defines the iconv charset name */
135 char *bidi
; /* if not null a fribidi charset */
136 short encoding_type
; /* encoding: font, utf8 or usc2 */
137 char *translit_csname
; /* iconv csname for transliteration */
140 typedef struct _FlocaleFont
142 struct _FlocaleFont
*next
;
145 XFontStruct
*font
; /* font structure */
146 XFontSet fontset
; /* font set */
147 FftFontType fftf
; /* fvwm xft font */
148 FlocaleCharset
*fc
; /* fvwm charset of the font */
149 FlocaleCharset
*str_fc
; /* fvwm charset of the strings to be displayed */
150 int height
; /* height of the font: ascent + descent */
158 unsigned shadow_dir
: (DIR_ALL_MASK
+ 1);
159 unsigned must_free_fc
: 1;
160 /* is_mb are used only with a XFontStruct font, for XFontSet
161 * everything is done in the good way automatically and this
162 * parameters is not needed */
163 unsigned is_mb
: 1; /* if true the font is a 2 bytes font */
170 char *e_str
; /* tmp */
171 XChar2b
*str2b
; /* tmp */
173 colorset_t
*colorset
;
181 unsigned text_rotation
: 2;
182 unsigned has_colorset
: 1;
183 unsigned has_clip_region
: 1;
200 multi_direction_t direction
;
206 unsigned sdir
: (DIR_ALL_MASK
+ 1);
210 /* ---------------------------- exported variables (globals) --------------- */
212 /* ---------------------------- interface functions ------------------------ */
215 * i18n X initialization
216 * category: the usual category LC_CTYPE, LC_CTIME, ...
217 * modifier: "" or NULL if NULL XSetLocaleModifiers is not called
218 * module: the name of the fvwm module that call the function for reporting
220 * The locale and the modifiers is sotred in Flocale and Fmodifiers.
221 * Flocale is set to NULL if the locale is not supported by the Xlib.
222 * In this case the Flocale* functions below does not use the Xmb* functions
224 * The function should be called as FlocaleInit(LC_CTYPE, "", "", "myname");
227 int category
, const char *local
, const char *modifier
,
235 * load a FlocaleFont (create it or load it from a cache)
236 * fontname: a ";" sperated list of "," separated list of XFLD font names or
237 * either "xft:" followed by a Xft font name. Examples:
238 * "xft:Verdana:Bold:pixelsize=14:rgba=rgb"
239 * "xft:Verdana:size=12;-adobe-courier-medium-r-normal--14-*,fixed"
240 * module: name of the fvwm module for errors msg
241 * If fontname is NULL the "default font" is loaded (2,3,4).
242 * The following logic is used:
243 * 0) If fontname has been has been already loaded the cache is used
244 * 1) We try to load each element "fn" of the ";" seprated list until success
246 * a - if fn begin with "xft:", then if FftSupport fn is loaded as an xft
247 * font; if !FftSupport fn is skipped (ignored)
248 * b - If the locale is supported fn is loaded using XCreateFontSet. If this
249 * fail fallback into 1-c)
250 * c - If the locale is not supported or 1-b fail fn is loaded using
251 * XLoadQueryFont (the first loadable font in the fn "," separated list
253 * 2) If 0) and 1) fail:
254 * - try to load MB_FALLBACK_FONT with XCreateFontSet
255 * - If this fail try to load FALLBACK_FONT with XLoadQueryFont
256 * 3) If everything fail the function return NULL.
258 * If font loading succed. Only one of the font, fontset, fftfont member of the
259 * FlocaleFont structure is not NULL/None. The caller should use this to
260 * set appropriately the gc member of the FlocaleWinString struct (the fid
261 * gc member should be set only if font is not NULL).
264 FlocaleFont
*FlocaleLoadFont(Display
*dpy
, char *fontname
, char *module
);
267 * unload the flf FlocaleFont
269 void FlocaleUnloadFont(Display
*dpy
, FlocaleFont
*flf
);
276 * Draw the text specified in fstring->str using fstring->gc as GC on the
277 * fstring->win window at position fstring->{x,y} using the ff FlocaleFont.
278 * If flags & FWS_HAVE_LENGTH, the fstring->len first characters of the
279 * string is drawn. If !(flags & FWS_HAVE_LENGTH), the function draw the
280 * the all string (fstring->len is ignored). Note that if ff->font is NULL
281 * the gc should not conatins a GCFont, as if ff->font != NULL the GCFont
282 * value should be ff->font->fid
284 void FlocaleDrawString(
285 Display
*dpy
, FlocaleFont
*ff
, FlocaleWinString
*fstring
,
286 unsigned long flags
);
289 * Underline a character in a string (pete@tecc.co.uk) at coffest position
291 void FlocaleDrawUnderline(
292 Display
*dpy
, FlocaleFont
*flf
, FlocaleWinString
*fws
, int coffset
);
295 * Get the position for shadow text
297 void FlocaleInitGstpArgs(
298 flocale_gstp_args
*args
, FlocaleFont
*flf
, FlocaleWinString
*fws
,
299 int start_x
, int start_y
);
301 Bool
FlocaleGetShadowTextPosition(
302 int *x
, int *y
, flocale_gstp_args
*args
);
305 * Call XmbTextEscapement(ff->fontset, str, sl) if ff->fontset is not None.
306 * Call XTextWith(ff->font, str, sl) if ff->font is not NULL.
307 * If sl is negative, the string is considered to be a vertival string and
308 * the function returns the height of the text.
310 int FlocaleTextWidth(FlocaleFont
*ff
, char *str
, int sl
);
313 * "y" (or "x" position if rotated and Xft font) of the text relatively to 0
315 int FlocaleGetMinOffset(FlocaleFont
*flf
, rotation_t rotation
);
318 * Allocate memory for a FlocaleWinString intialized to 0
320 void FlocaleAllocateWinString(FlocaleWinString
**pfws
);
327 * return the window or icon name of a window w
328 * func: XGetWMName or XGetWMIconName
330 * w: the window for which we want the (icon) name
332 * ret_name: the icon or the window name of the window
334 void FlocaleGetNameProperty(
335 Status (func
)(Display
*, Window
, XTextProperty
*), Display
*dpy
,
336 Window w
, FlocaleNameString
*ret_name
);
339 * Free the name property allocated with FlocaleGetNameProperty
341 void FlocaleFreeNameProperty(
342 FlocaleNameString
*ptext
);
345 * Simple warper to XmbTextListToTextProperty (FlocaleMultibyteSupport and the
346 * locale is supported by the xlib) or XStringListToTextProperty
348 Bool
FlocaleTextListToTextProperty(
349 Display
*dpy
, char **list
, int count
, XICCEncodingStyle style
,
350 XTextProperty
*text_prop_return
);
355 void FlocalePrintLocaleInfo(Display
*dpy
, int verbose
);
361 /* return number of bytes of character at current position
362 (pointed to by str) */
363 int FlocaleStringNumberOfBytes(FlocaleFont
*flf
, const char *str
);
365 /* given a string, font specifying its locale and a byte offset gives
367 int FlocaleStringByteToCharOffset(FlocaleFont
*flf
, const char *str
,
370 /* like above but reversed, ie. return byte offset corresponding to given
372 int FlocaleStringCharToByteOffset(FlocaleFont
*flf
, const char *str
,
375 /* return length of string in characters */
376 int FlocaleStringCharLength(FlocaleFont
*flf
, const char *str
);
379 #endif /* FLOCALE_H */