Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Blame | Last modification | View Log | Download | RSS feed

  1. /*
  2.  * Copyright 2003 Phil Mellor <monkeyson@users.sourceforge.net>
  3.  * Copyright 2005 James Bursa <bursa@users.sourceforge.net>
  4.  * Copyright 2004 John Tytgat <joty@netsurf-browser.org>
  5.  *
  6.  * This file is part of NetSurf, http://www.netsurf-browser.org/
  7.  *
  8.  * NetSurf is free software; you can redistribute it and/or modify
  9.  * it under the terms of the GNU General Public License as published by
  10.  * the Free Software Foundation; version 2 of the License.
  11.  *
  12.  * NetSurf is distributed in the hope that it will be useful,
  13.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15.  * GNU General Public License for more details.
  16.  *
  17.  * You should have received a copy of the GNU General Public License
  18.  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  19.  */
  20.  
  21. /** \file
  22.  * Font handling (interface).
  23.  *
  24.  * These functions provide font related services. They all work on UTF-8 strings
  25.  * with lengths given.
  26.  *
  27.  * Note that an interface to painting is not defined here. Painting is
  28.  * redirected through platform-dependent plotters anyway, so there is no gain in
  29.  * abstracting it here.
  30.  */
  31.  
  32. #ifndef _NETSURF_RENDER_FONT_H_
  33. #define _NETSURF_RENDER_FONT_H_
  34.  
  35. #include <stdbool.h>
  36. #include <stddef.h>
  37.  
  38. #include "css/css.h"
  39. #include "desktop/plot_style.h"
  40.  
  41. struct font_functions
  42. {
  43.         /**
  44.          * Measure the width of a string.
  45.          *
  46.          * \param  fstyle  plot style for this text
  47.          * \param  string  UTF-8 string to measure
  48.          * \param  length  length of string, in bytes
  49.          * \param  width   updated to width of string[0..length)
  50.          * \return  true on success, false on error and error reported
  51.          */
  52.         bool (*font_width)(const plot_font_style_t *fstyle,
  53.                         const char *string, size_t length,
  54.                         int *width);
  55.         /**
  56.          * Find the position in a string where an x coordinate falls.
  57.          *
  58.          * \param  fstyle       style for this text
  59.          * \param  string       UTF-8 string to measure
  60.          * \param  length       length of string, in bytes
  61.          * \param  x            x coordinate to search for
  62.          * \param  char_offset  updated to offset in string of actual_x, [0..length]
  63.          * \param  actual_x     updated to x coordinate of character closest to x
  64.          * \return  true on success, false on error and error reported
  65.          */
  66.         bool (*font_position_in_string)(const plot_font_style_t *fstyle,
  67.                         const char *string, size_t length,
  68.                         int x, size_t *char_offset, int *actual_x);
  69.         /**
  70.          * Find where to split a string to make it fit a width.
  71.          *
  72.          * \param  fstyle       style for this text
  73.          * \param  string       UTF-8 string to measure
  74.          * \param  length       length of string, in bytes
  75.          * \param  x            width available
  76.          * \param  char_offset  updated to offset in string of actual_x, [0..length]
  77.          * \param  actual_x     updated to x coordinate of character closest to x
  78.          * \return  true on success, false on error and error reported
  79.          *
  80.          * On exit, [char_offset == 0 ||
  81.          *           string[char_offset] == ' ' ||
  82.          *           char_offset == length]
  83.          */
  84.         bool (*font_split)(const plot_font_style_t *fstyle,
  85.                         const char *string, size_t length,
  86.                         int x, size_t *char_offset, int *actual_x);
  87. };
  88.  
  89. extern const struct font_functions nsfont;
  90.  
  91. void font_plot_style_from_css(const css_computed_style *css,
  92.                 plot_font_style_t *fstyle);
  93.  
  94. #endif
  95.