font 19 KB
Newer Older
Neil Turton's avatar
Neil Turton committed
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
/* Copyright 1996 Acorn Computers Ltd
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
/****************************************************************************
 * This source file was written by Acorn Computers Limited. It is part of   *
 * the RISCOS library for writing applications in C for RISC OS. It may be  *
 * used freely in the creation of programs for Archimedes. It should be     *
 * used with Acorn's C Compiler Release 3 or later.                         *
 *                                                                          *
 ***************************************************************************/

/*
 * Title  : font.h
 * Purpose: access to RISC OS font facilities
 *
 */

# ifndef __font_h
# define __font_h

# include <stddef.h>

# ifndef __os_h
# include "os.h"
# endif

# ifndef __drawmod_h
# include "drawmod.h"
# endif

# ifndef __wimp_h
# include "wimp.h"
# endif

typedef int font; /* abstract font handle */


/* ---------------------------- font_cacheaddress --------------------------
 * Description:   Informs caller of font cache used and font cache size.
 *
 * Parameters:    int *version -- version number
 *                int *cacheused -- amount of font cache used (in bytes)
 *                int *cachesize -- total size of font cache (in bytes)
 * Returns:       os_error* -- possible error condition
 * Other Info:    Version number is *100, so v.1.07 would be returned as 107.
 *
 */

extern os_error * font_cacheaddress(int *version, int *cacheused, int *cachesize);


/* ------------------------------- font_find -------------------------------
 * Description:   Gives caller a handle to font, given its name.
 *
 * Parameters:    char *name -- the font name
 *                int xsize, ysize -- x/y point size (in 16ths of a point)
 *                int xres, yres -- x/y resolution in dots per inch
 *                font* -- the returned font handle
 * Returns:       Possible error condition.
 * Other Info:    none.
 *
 */

extern os_error * font_find(
  char* name,
  int xsize, int ysize,    /* in 16ths of a point */
  int xres, int yres,      /* dots per inch of resolution: 0->use default */
  font*);                  /* result */


/* ------------------------------- font_lose -------------------------------
 * Description:   Informs font manager that a font is no longer needed
 *
 * Parameters:    font f -- the font
 * Returns:       possible error condition.
 * Other Info:    none.
 *
 */

extern os_error * font_lose(font f);

typedef struct font_def {
    char name[16];
    int xsize, ysize, xres, yres; /* as above */
    int usage, age;
} font_def;


/* ------------------------------ font_readdef -----------------------------
 * Description:   Get details about a font, given its handle.
 *
 * Parameters:    font -- the font handle
 *                font_def* -- pointer to buffer to hold returned details
 * Returns:       possible error condition.
 * Other Info:    This function fills in details re: font, into the supplied
 *                buffer(a variable of type 'font_def').
 *                fields of this buffer are as follows:
 *                          name -- font name
 *                          xsize, ysize -- x/y point size * 16
 *                          xres, yres -- x/y resolution (dots per inch)
 *                          usage -- number of times Font_FindFont has found
 *                                   the font minus number of times
 *                                   Font_LoseFont has been used on it
 *                          age -- number of font accesses made since this
 *                                 one was last accessed.
 *
 */

extern os_error * font_readdef(font, font_def*);

typedef struct font_info {
    int minx, miny, maxx, maxy;
} font_info;


/* ------------------------------- font_readinfo ---------------------------
 * Description:   Informs caller of minimal area covering any character in
 *                the font bounding box.
 *
 * Parameters:    font -- the font handle
 *                font_info* -- pointer to buffer to hold returned details
 * Returns:       possible error condition.
 * Other Info:    Fills in details re: font in supplied buffer (variable of
 *                type 'font_info').
 *                fields of this buffer are as follows:
 *                       minx -- min x coord in pixels (inclusive)
 *                       maxx -- max x coord in pixels (inclusive)
 *                       miny -- min y coord in pixels (exclusive)
 *                       maxy -- max y coord in pixels (exclusive).
 *
 */

extern os_error * font_readinfo(font, font_info*);


typedef struct font_string {

    char* s;
    int x;                /* inout, in 1/72000 inch */
    int y;                /* inout, in 1/72000 inch */
    int split;            /* inout: space char, or -1 */
                          /* on exit, = count of space or printable */
    int term;             /* inout, index into s */

    } font_string;


/* -------------------------------- font_strwidth --------------------------
 * Description:   Determine 'width' of string.
 *
 * Parameters:    font_string *fs -- the string, with fields:
 *                              s -- string itself
 *                              x -- max x offset before termination
 *                              y -- max y offset before termination
 *                          split -- string split character
 *                           term -- index of char to terminate by
 * Returns:       possible error condition.
 * Other Info:    On exit fs fields hold:
 *                              s -- unchanged
 *                              x -- x offset after printing string
 *                              y -- y offset after printing string
 *                          split -- no. of split chars found
 *                                   no. of printable chars if split was -1
 *                           term -- index into string at which terminated.
 *
 */

extern os_error * font_strwidth(font_string *fs);


/* paint options */
Kevin Bracey's avatar
Kevin Bracey committed
183 184 185
#define font_JUSTIFY  0x0001  /* justify text */
#define font_RUBOUT   0x0002  /* rub-out box required */
#define font_ABS      0x0004  /* absolute co-ordinates */
Neil Turton's avatar
Neil Turton committed
186
        /* 8 not used */
Kevin Bracey's avatar
Kevin Bracey committed
187 188 189 190
#define font_OSCOORDS 0x0010  /* os coords supplied (otherwise 1/72000 inch) */
#define font_LENGTH   0x0080  /* length supplied */
#define font_16BIT    0x1000  /* 16-bit string supplied */
#define font_32BIT    0x2000  /* 32-bit string supplied */
Neil Turton's avatar
Neil Turton committed
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


/* ------------------------------- font_paint -----------------------------
 * Description:   Paint the given string at coords x,y.
 *
 * Parameters:    char * -- the string
 *                int options -- set using "paint options" defined above
 *                int x, y -- coords (either os or 1/72000 inch)
 * Returns:       possible error condition.
 * Other Info:    none.
 *
 */

extern os_error * font_paint(char*, int options, int x, int y);


/* ------------------------------- font_caret -----------------------------
 * Description:   Set colour, size and position of the caret.
 *
 * Parameters:    int colour -- EORed onto screen
 *                int height -- in OS coordinates
 *                int flags -- bit 4 set ==> OS coords, else 1/72000 inch
 *                int x,y   -- x/y coords
 * Returns:       possible error condition.
 * Other Info:    none.
 *
 */

extern os_error *font_caret(int colour, int height, int flags, int x, int y);


/* ---------------------------- font_converttoos ---------------------------
 * Description:   Converts coords in 1/72000 inch to OS units.
 *
 * Parameters:    int x_inch, y_inch -- x/y coords in 1/72000 inch
 *                int *x_os, *y_os -- x/y coords in OS units
 * Returns:       possible error condition.
 * Other Info:    none.
 *
 */

extern os_error *font_converttoos(int x_inch, int y_inch, int *x_os, int *y_os);


/* --------------------------- font_converttopoints ------------------------
 * Description:   Converts OS units to 1/72000 inch.
 *
 * Parameters:    int x_os, y_os -- x/y coords in OS units
 *                int *x_inch, *y_inch -- x/y coords in 1/72000 inch
 * Returns:       possible error condition.
 * Other Info:    none.
 *
 */

extern os_error *font_converttopoints(int x_os, int y_os, int *x_inch, int *y_inch);


/* ------------------------------- font_setfont ----------------------------
 * Description:   Sets up font used for subsequent painting or size-requests.
 *
 * Parameters:    font -- the font handle
 * Returns:       possible error condition.
 * Other Info:    none.
 *
 */

extern os_error * font_setfont(font);


typedef struct font_state {

       font f;
       int back_colour;
       int fore_colour;
       int offset;

       } font_state;


/* --------------------------------- font_current --------------------------
 * Description:   Informs caller of current font state.
 *
 * Parameters:    font_state *f -- pointer to buffer to hold font state
 * Returns:       possible error condition.
 * Other Info:    returned buffer(into variable of type 'font_state'):
 *                         font f -- handle of current font
 *                         int back_colour -- current background colour
 *                         int fore_colour -- current foreground colour
 *                         int offset -- foreground colour offset.
 *
 */

extern os_error *font_current(font_state *f);


/* -------------------------------- font_future ----------------------------
 * Description:   Informs caller of font characteristics after a future
 *                font_paint.
 *
 * Parameters:    font_state *f -- pointer to buffer to hold font state
 * Returns:       possible error condition.
 * Other Info:    buffer contents:
 *                          font f -- handle of font which would be selected
 *                          int back_colour -- future background colour
 *                          int fore_colour -- future foreground colour
 *                          int offset -- foreground colour offset.
 *
 */

extern os_error *font_future(font_state *f);


/* ------------------------------- font_findcaret --------------------------
 * Description:   Informs caller of nearest point in a string to the caret
 *                position.
 *
 * Parameters:    font_string *fs -- the string
 *                         fields:  char *s -- the string itself
 *                                  int x,y -- x/y coords of caret
 * Returns:       possible error condition.
 * Other Info:    returned fields of fs as in font_strwidth.
 *
 */

extern os_error *font_findcaret(font_string *fs);


/* ----------------------------- font_charbbox -----------------------------
 * Description:   Informs caller of bounding box of char in given font.
 *
 * Parameters:    font -- the font handle
 *                char -- the ASCII character
 *                int options -- only relevant option if font_OSCOORDS
 *                font_info * -- pointer to buffer to hold font info
 * Returns:       possible error condition.
 * Other Info:    if OS coords are used and font has been scaled, box may
 *                be surrounded by area of blank pixels.
 *
 */

extern os_error * font_charbbox(font, char, int options, font_info*);


/* -------------------------- font_readscalefactor -------------------------
 * Description:   Informs caller of x and y scale factors used by font.
 *                manager for converting between OS coords and 1/72000 inch
 *
 * Parameters:    int *x, *y -- returned scale factors
 * Returns:       possible error condition.
 * Other Info:    none.
 *
 */

extern os_error *font_readscalefactor(int *x, int *y);


/* ---------------------------- font_setscalefactor -----------------------
 * Description:   Sets the scale factors used by font manager.
 *
 * Parameters:    int x,y -- the new scale factors
 * Returns:       possible error condition.
 * Other Info:    scale factors may have been changed by another application
 *                well-behaved applications save and restore scale factors.
 *
 */

extern os_error *font_setscalefactor(int x, int y);


/* ------------------------------- font_list -------------------------------
 * Description:   Gives name of an available font.
 *
 * Parameters:    char* -- pointer to buffer to hold font name
 *                int*  -- count of fonts found (0 on first call)
 * Returns:       possible error condition.
 * Other Info:    count is -1 if no more names
 *                typically used in loop until count == -1.
 *
 */

extern os_error * font_list(char*, int*);


/* ------------------------------ font_setcolour ---------------------------
 * Description:   Sets the current font(optionally), changes foreground
 *                and background colours, and offset for that font.
 *
 * Parameters:    font -- the font handle (0 for current font)
 *                int background, foreground -- back/foreground colours
 *                int offset -- foreground offset colour (-14 to +14)
 * Returns:       possible error condition.
 * Other Info:    none.
 *
 */

extern os_error * font_setcolour(font, int background, int foreground, int offset);


#define font_BlueGun  0x01000000 /* 8-bit field: phsical colour blue gun.  */
#define font_GreenGun 0x00010000 /* 8-bit field: phsical colour green gun. */
#define font_RedGun   0x00000100 /* 8-bit field: phsical colour red gun.   */


/* --------------------------- font_setpalette -----------------------------
 * Description:   Sets the anti-alias palette
 *
 * Parameters:    int background -- logical background colour
 *                int foreground -- logical foreground colour
 *                int offset -- foreground colour offset
 *                int physical_back -- physical background colour
 *                int physical_fore -- physical foreground colour
 * Returns:       possible error condition.
 * Other Info:    physical_back and physical_fore are of the form:
 *                        0xBBGGRR00 (see #defines above).
 *
 */

extern os_error *font_setpalette(int background, int foreground, int offset,
                          int physical_back, int physical_fore);

typedef struct font_threshold {

     char offset;
     char thresholds[15];

     } font_threshold;


/* ------------------------- font_readthresholds ---------------------------
 * Description:   Reads the list of threshold values that the font manager
 *                uses when painting characters.
 *
 * Parameters:    font_theshold *th -- pointer to result buffer
 * Returns:       possible error condition.
 * Other Info:    none.
 *
 */

extern os_error *font_readthresholds(font_threshold *th);


/* ------------------------- font_setthresholds ----------------------------
 * Description:   Sets up threshold values for painting colours.
 *
 * Parameters:    font_threshold *th -- pointer to a threshold table
 * Returns:       possible error condition.
 * Other Info:    none.
 *
 */

extern os_error *font_setthresholds(font_threshold *th);


/* ------------------------- font_findcaretj -------------------------------
 * Description:   Finds nearest point where the caret can go (using
 *                justification offsets).
 *
 * Parameters:    font_string *fs -- the string (set up as in font_findcaret)
 *                int offset_x, offset-y -- the justification offsets
 * Returns:       possible error condition.
 * Other Info:    if offsets are both zero then same as font_findcaret.
 *
 */

extern os_error *font_findcaretj(font_string *fs, int offset_x, int offset_y);


/* ------------------------ font_stringbbox --------------------------------
 * Description:   Measures the size of a string (without printing it).
 *
 * Parameters:    char *s -- the string
 *                font_info *fi -- pointer to buffer to hold font info
 * Returns:       possible error condition.
 * Other Info:    fields returned in fi are:
 *                    minx, miny -- bounding box min x/y
 *                    maxx, maxy -- bounding box min x/y.
 *
 */

extern os_error *font_stringbbox(char *s, font_info *fi);

/*---------------------------------------------------------------------------*/
/*Routines to create a draw module path object from calls to font_paint*/

typedef enum {font_CONVERT, font_IGNORE, font_ERROR} font_action_on_bitmap;

extern os_error
   *font_output_to_null
   (  BOOL add_hints,
      BOOL output_skeleton,
      font_action_on_bitmap action_on_bitmap
   );

extern os_error *font_output_size (size_t *size);

extern os_error
   *font_output_to_buffer
   (  drawmod_buffer *buff_ptr,
      BOOL add_hints,
      BOOL output_skeleton,
      font_action_on_bitmap action_on_bitmap
   );

extern os_error *font_output_to_screen (void);

/* ------------------------ font_makemenu --------------------------------
 * Description:   Constructs a Wimp menu of all available fonts
 *
 * Parameters:    wimp_menustr ** menup   -- on entry, *menup = result from last time, or NULL
 *                char * tickitem         -- font identifier to tick, else NULL => none, or 1 => system font
 *                fontmenu_flags flags    -- 0 => construct menu without 'System font' at top
 *                                           1 => construct menu with 'System font' at top
 *                                           2 => just delete the supplied menu structure
 * Returns:       possible error condition
 * Other Info:    *menup -> font menu (suitable for passing to Wimp_CreateMenu)
 *
 */

typedef enum {
  fontmenu_WithoutSystemFont = 0,
  fontmenu_WithSystemFont    = 1,
  fontmenu_Delete            = 2
} fontmenu_flags;

extern os_error *font_makemenu(wimp_menustr ** menup, char * tickitem, fontmenu_flags flags);

/* ------------------------ font_decodemenu --------------------------------
 * Description:   Decodes a menu click in a font menu
 *
 * Parameters:    wimp_menustr * menu     -- pointer to font menu
 *                int * selections        -- list of menu selection indices
 *                char ** resultp         -- pointer to pointer to contain answer
 *                                           *resultp -> previous buffer, or NULL
 * Returns:       possible error condition
 * Other Info:    *resultp -> malloc block containing font identifier
 *                the initial value of *resultp is realloc()ed to obtain the new buffer
 *                the resulting buffer should be free()ed by the caller when no longer required
 *
 *                if menu includes system font, check for selections[0]==0 before calling this
 *                (font_decodemenu will return "System font", which isn't very useful)
 *                The format of the font identifier string is documented in the Font Manager spec.
 */

extern os_error *font_decodemenu(wimp_menustr * menu, int * selections, char ** resultp);

# endif

/* end font.h */