/************************************************************
**
** Application: CJLib
**
** Title:       c.fonts
**
*************************************************************/

/* Include files */
/* from standard clib */
//#include <stdlib.h>
//#include <stdio.h>

/* from oslib */
#include "oslib/font.h"

/* from CJLib */
//#include "CJLib:etc.h"

/* from application */
#include "fonts.h"



/************************************************************/

/* exported variables */

/* global variables */

/* forward function declarations */


/************************************************************/





void FontL_scan_string ( font_f fhandle,
                         char *text,
                         font_string_flags flags,
                         int x,
                         int y,
                         os_trfm *trfm,
                         char **split_point,
                         int *x_out,
                         int *y_out,
                         int *length_out,
                         os_box *box )

{
  font_scan_block   block;

  block.split_char = -1;
  block.space.x    = 0;
  block.space.y    = 0;
  block.letter.x   = 0;
  block.letter.y   = 0;
  block.bbox.x0    = 0;
  block.bbox.y0    = 0;
  block.bbox.x1    = 0;
  block.bbox.y1    = 0;

  font_scan_string ( fhandle,
                     text,
                     flags,
                     x,
                     y,
                     &block,
                     trfm,
                     0,
                     split_point,
                     x_out,
                     y_out,
                     length_out );

  if (box) *box = block.bbox;
  return;
}




/*********************************************************************/

void FontL_string_bbox ( font_f fhandle, char *text, os_trfm *trfm, os_box *box )

{
  font_string_flags flags;
  int x_out, y_out, length_out;


  flags = font_GIVEN_BLOCK | font_GIVEN_FONT | font_GIVEN_TRFM
                           | font_RETURN_BBOX | font_KERN ;


  FontL_scan_string ( fhandle,
                      text,
                      flags,
                      0x7FFFFFFF,
                      0x7FFFFFFF,
                      trfm,
                      NULL,
                      &x_out,
                      &y_out,
                      &length_out,
                      box );


  return;
}




/*********************************************************************/

void FontL_string_ht_and_wid ( font_f fhandle,
                               char *text, int *ht, int *wid, int return_units )

{
  int h, w;
  os_box bbox;


  /* Normal text, no transform needed */
  FontL_string_bbox (fhandle, text, NULL, &bbox);

  h = bbox.y1 - bbox.y0 ;
  w = bbox.x1 - bbox.x0 ;
  switch (return_units)
  {
    case RETURN_DRAWUNITS:
      /* multiply returned sizes by 256 for draw units */
      h = h << 8;
      w = w << 8;
    case RETURN_OSUNITS:
      font_convertto_os ( h, w, ht, wid );
      break;

    case RETURN_MPTS:
    default:
      *ht = h;
      *wid = w;
  }

  return;
}







/*********************************************************************/

