ftstroke.h

Go to the documentation of this file.
00001 /***************************************************************************/
00002 /*                                                                         */
00003 /*  ftstroke.h                                                             */
00004 /*                                                                         */
00005 /*    FreeType path stroker (specification).                               */
00006 /*                                                                         */
00007 /*  Copyright 2002, 2003, 2004, 2005, 2006, 2008, 2009 by                  */
00008 /*  David Turner, Robert Wilhelm, and Werner Lemberg.                      */
00009 /*                                                                         */
00010 /*  This file is part of the FreeType project, and may only be used,       */
00011 /*  modified, and distributed under the terms of the FreeType project      */
00012 /*  license, LICENSE.TXT.  By continuing to use, modify, or distribute     */
00013 /*  this file you indicate that you have read the license and              */
00014 /*  understand and accept it fully.                                        */
00015 /*                                                                         */
00016 /***************************************************************************/
00017 
00018 
00019 #ifndef __FT_STROKE_H__
00020 #define __FT_STROKE_H__
00021 
00022 #include <ft2build.h>
00023 #include FT_OUTLINE_H
00024 #include FT_GLYPH_H
00025 
00026 
00027 FT_BEGIN_HEADER
00028 
00029 
00030  /************************************************************************
00031   *
00032   * @section:
00033   *    glyph_stroker
00034   *
00035   * @title:
00036   *    Glyph Stroker
00037   *
00038   * @abstract:
00039   *    Generating bordered and stroked glyphs.
00040   *
00041   * @description:
00042   *    This component generates stroked outlines of a given vectorial
00043   *    glyph.  It also allows you to retrieve the `outside' and/or the
00044   *    `inside' borders of the stroke.
00045   *
00046   *    This can be useful to generate `bordered' glyph, i.e., glyphs
00047   *    displayed with a coloured (and anti-aliased) border around their
00048   *    shape.
00049   */
00050 
00051 
00052  /**************************************************************
00053   *
00054   * @type:
00055   *   FT_Stroker
00056   *
00057   * @description:
00058   *   Opaque handler to a path stroker object.
00059   */
00060   typedef struct FT_StrokerRec_*  FT_Stroker;
00061 
00062 
00063   /**************************************************************
00064    *
00065    * @enum:
00066    *   FT_Stroker_LineJoin
00067    *
00068    * @description:
00069    *   These values determine how two joining lines are rendered
00070    *   in a stroker.
00071    *
00072    * @values:
00073    *   FT_STROKER_LINEJOIN_ROUND ::
00074    *     Used to render rounded line joins.  Circular arcs are used
00075    *     to join two lines smoothly.
00076    *
00077    *   FT_STROKER_LINEJOIN_BEVEL ::
00078    *     Used to render beveled line joins; i.e., the two joining lines
00079    *     are extended until they intersect.
00080    *
00081    *   FT_STROKER_LINEJOIN_MITER ::
00082    *     Same as beveled rendering, except that an additional line
00083    *     break is added if the angle between the two joining lines
00084    *     is too closed (this is useful to avoid unpleasant spikes
00085    *     in beveled rendering).
00086    */
00087   typedef enum  FT_Stroker_LineJoin_
00088   {
00089     FT_STROKER_LINEJOIN_ROUND = 0,
00090     FT_STROKER_LINEJOIN_BEVEL,
00091     FT_STROKER_LINEJOIN_MITER
00092 
00093   } FT_Stroker_LineJoin;
00094 
00095 
00096   /**************************************************************
00097    *
00098    * @enum:
00099    *   FT_Stroker_LineCap
00100    *
00101    * @description:
00102    *   These values determine how the end of opened sub-paths are
00103    *   rendered in a stroke.
00104    *
00105    * @values:
00106    *   FT_STROKER_LINECAP_BUTT ::
00107    *     The end of lines is rendered as a full stop on the last
00108    *     point itself.
00109    *
00110    *   FT_STROKER_LINECAP_ROUND ::
00111    *     The end of lines is rendered as a half-circle around the
00112    *     last point.
00113    *
00114    *   FT_STROKER_LINECAP_SQUARE ::
00115    *     The end of lines is rendered as a square around the
00116    *     last point.
00117    */
00118   typedef enum  FT_Stroker_LineCap_
00119   {
00120     FT_STROKER_LINECAP_BUTT = 0,
00121     FT_STROKER_LINECAP_ROUND,
00122     FT_STROKER_LINECAP_SQUARE
00123 
00124   } FT_Stroker_LineCap;
00125 
00126 
00127   /**************************************************************
00128    *
00129    * @enum:
00130    *   FT_StrokerBorder
00131    *
00132    * @description:
00133    *   These values are used to select a given stroke border
00134    *   in @FT_Stroker_GetBorderCounts and @FT_Stroker_ExportBorder.
00135    *
00136    * @values:
00137    *   FT_STROKER_BORDER_LEFT ::
00138    *     Select the left border, relative to the drawing direction.
00139    *
00140    *   FT_STROKER_BORDER_RIGHT ::
00141    *     Select the right border, relative to the drawing direction.
00142    *
00143    * @note:
00144    *   Applications are generally interested in the `inside' and `outside'
00145    *   borders.  However, there is no direct mapping between these and the
00146    *   `left' and `right' ones, since this really depends on the glyph's
00147    *   drawing orientation, which varies between font formats.
00148    *
00149    *   You can however use @FT_Outline_GetInsideBorder and
00150    *   @FT_Outline_GetOutsideBorder to get these.
00151    */
00152   typedef enum  FT_StrokerBorder_
00153   {
00154     FT_STROKER_BORDER_LEFT = 0,
00155     FT_STROKER_BORDER_RIGHT
00156 
00157   } FT_StrokerBorder;
00158 
00159 
00160   /**************************************************************
00161    *
00162    * @function:
00163    *   FT_Outline_GetInsideBorder
00164    *
00165    * @description:
00166    *   Retrieve the @FT_StrokerBorder value corresponding to the
00167    *   `inside' borders of a given outline.
00168    *
00169    * @input:
00170    *   outline ::
00171    *     The source outline handle.
00172    *
00173    * @return:
00174    *   The border index.  @FT_STROKER_BORDER_RIGHT for empty or invalid
00175    *   outlines.
00176    */
00177   FT_EXPORT( FT_StrokerBorder )
00178   FT_Outline_GetInsideBorder( FT_Outline*  outline );
00179 
00180 
00181   /**************************************************************
00182    *
00183    * @function:
00184    *   FT_Outline_GetOutsideBorder
00185    *
00186    * @description:
00187    *   Retrieve the @FT_StrokerBorder value corresponding to the
00188    *   `outside' borders of a given outline.
00189    *
00190    * @input:
00191    *   outline ::
00192    *     The source outline handle.
00193    *
00194    * @return:
00195    *   The border index.  @FT_STROKER_BORDER_LEFT for empty or invalid
00196    *   outlines.
00197    */
00198   FT_EXPORT( FT_StrokerBorder )
00199   FT_Outline_GetOutsideBorder( FT_Outline*  outline );
00200 
00201 
00202   /**************************************************************
00203    *
00204    * @function:
00205    *   FT_Stroker_New
00206    *
00207    * @description:
00208    *   Create a new stroker object.
00209    *
00210    * @input:
00211    *   library ::
00212    *     FreeType library handle.
00213    *
00214    * @output:
00215    *   astroker ::
00216    *     A new stroker object handle.  NULL in case of error.
00217    *
00218    * @return:
00219    *    FreeType error code.  0~means success.
00220    */
00221   FT_EXPORT( FT_Error )
00222   FT_Stroker_New( FT_Library   library,
00223                   FT_Stroker  *astroker );
00224 
00225 
00226   /**************************************************************
00227    *
00228    * @function:
00229    *   FT_Stroker_Set
00230    *
00231    * @description:
00232    *   Reset a stroker object's attributes.
00233    *
00234    * @input:
00235    *   stroker ::
00236    *     The target stroker handle.
00237    *
00238    *   radius ::
00239    *     The border radius.
00240    *
00241    *   line_cap ::
00242    *     The line cap style.
00243    *
00244    *   line_join ::
00245    *     The line join style.
00246    *
00247    *   miter_limit ::
00248    *     The miter limit for the FT_STROKER_LINEJOIN_MITER style,
00249    *     expressed as 16.16 fixed point value.
00250    *
00251    * @note:
00252    *   The radius is expressed in the same units as the outline
00253    *   coordinates.
00254    */
00255   FT_EXPORT( void )
00256   FT_Stroker_Set( FT_Stroker           stroker,
00257                   FT_Fixed             radius,
00258                   FT_Stroker_LineCap   line_cap,
00259                   FT_Stroker_LineJoin  line_join,
00260                   FT_Fixed             miter_limit );
00261 
00262 
00263   /**************************************************************
00264    *
00265    * @function:
00266    *   FT_Stroker_Rewind
00267    *
00268    * @description:
00269    *   Reset a stroker object without changing its attributes.
00270    *   You should call this function before beginning a new
00271    *   series of calls to @FT_Stroker_BeginSubPath or
00272    *   @FT_Stroker_EndSubPath.
00273    *
00274    * @input:
00275    *   stroker ::
00276    *     The target stroker handle.
00277    */
00278   FT_EXPORT( void )
00279   FT_Stroker_Rewind( FT_Stroker  stroker );
00280 
00281 
00282   /**************************************************************
00283    *
00284    * @function:
00285    *   FT_Stroker_ParseOutline
00286    *
00287    * @description:
00288    *   A convenience function used to parse a whole outline with
00289    *   the stroker.  The resulting outline(s) can be retrieved
00290    *   later by functions like @FT_Stroker_GetCounts and @FT_Stroker_Export.
00291    *
00292    * @input:
00293    *   stroker ::
00294    *     The target stroker handle.
00295    *
00296    *   outline ::
00297    *     The source outline.
00298    *
00299    *   opened ::
00300    *     A boolean.  If~1, the outline is treated as an open path instead
00301    *     of a closed one.
00302    *
00303    * @return:
00304    *   FreeType error code.  0~means success.
00305    *
00306    * @note:
00307    *   If `opened' is~0 (the default), the outline is treated as a closed
00308    *   path, and the stroker generates two distinct `border' outlines.
00309    *
00310    *   If `opened' is~1, the outline is processed as an open path, and the
00311    *   stroker generates a single `stroke' outline.
00312    *
00313    *   This function calls @FT_Stroker_Rewind automatically.
00314    */
00315   FT_EXPORT( FT_Error )
00316   FT_Stroker_ParseOutline( FT_Stroker   stroker,
00317                            FT_Outline*  outline,
00318                            FT_Bool      opened );
00319 
00320 
00321   /**************************************************************
00322    *
00323    * @function:
00324    *   FT_Stroker_BeginSubPath
00325    *
00326    * @description:
00327    *   Start a new sub-path in the stroker.
00328    *
00329    * @input:
00330    *   stroker ::
00331    *     The target stroker handle.
00332    *
00333    *   to ::
00334    *     A pointer to the start vector.
00335    *
00336    *   open ::
00337    *     A boolean.  If~1, the sub-path is treated as an open one.
00338    *
00339    * @return:
00340    *   FreeType error code.  0~means success.
00341    *
00342    * @note:
00343    *   This function is useful when you need to stroke a path that is
00344    *   not stored as an @FT_Outline object.
00345    */
00346   FT_EXPORT( FT_Error )
00347   FT_Stroker_BeginSubPath( FT_Stroker  stroker,
00348                            FT_Vector*  to,
00349                            FT_Bool     open );
00350 
00351 
00352   /**************************************************************
00353    *
00354    * @function:
00355    *   FT_Stroker_EndSubPath
00356    *
00357    * @description:
00358    *   Close the current sub-path in the stroker.
00359    *
00360    * @input:
00361    *   stroker ::
00362    *     The target stroker handle.
00363    *
00364    * @return:
00365    *   FreeType error code.  0~means success.
00366    *
00367    * @note:
00368    *   You should call this function after @FT_Stroker_BeginSubPath.
00369    *   If the subpath was not `opened', this function `draws' a
00370    *   single line segment to the start position when needed.
00371    */
00372   FT_EXPORT( FT_Error )
00373   FT_Stroker_EndSubPath( FT_Stroker  stroker );
00374 
00375 
00376   /**************************************************************
00377    *
00378    * @function:
00379    *   FT_Stroker_LineTo
00380    *
00381    * @description:
00382    *   `Draw' a single line segment in the stroker's current sub-path,
00383    *   from the last position.
00384    *
00385    * @input:
00386    *   stroker ::
00387    *     The target stroker handle.
00388    *
00389    *   to ::
00390    *     A pointer to the destination point.
00391    *
00392    * @return:
00393    *   FreeType error code.  0~means success.
00394    *
00395    * @note:
00396    *   You should call this function between @FT_Stroker_BeginSubPath and
00397    *   @FT_Stroker_EndSubPath.
00398    */
00399   FT_EXPORT( FT_Error )
00400   FT_Stroker_LineTo( FT_Stroker  stroker,
00401                      FT_Vector*  to );
00402 
00403 
00404   /**************************************************************
00405    *
00406    * @function:
00407    *   FT_Stroker_ConicTo
00408    *
00409    * @description:
00410    *   `Draw' a single quadratic Bézier in the stroker's current sub-path,
00411    *   from the last position.
00412    *
00413    * @input:
00414    *   stroker ::
00415    *     The target stroker handle.
00416    *
00417    *   control ::
00418    *     A pointer to a Bézier control point.
00419    *
00420    *   to ::
00421    *     A pointer to the destination point.
00422    *
00423    * @return:
00424    *   FreeType error code.  0~means success.
00425    *
00426    * @note:
00427    *   You should call this function between @FT_Stroker_BeginSubPath and
00428    *   @FT_Stroker_EndSubPath.
00429    */
00430   FT_EXPORT( FT_Error )
00431   FT_Stroker_ConicTo( FT_Stroker  stroker,
00432                       FT_Vector*  control,
00433                       FT_Vector*  to );
00434 
00435 
00436   /**************************************************************
00437    *
00438    * @function:
00439    *   FT_Stroker_CubicTo
00440    *
00441    * @description:
00442    *   `Draw' a single cubic Bézier in the stroker's current sub-path,
00443    *   from the last position.
00444    *
00445    * @input:
00446    *   stroker ::
00447    *     The target stroker handle.
00448    *
00449    *   control1 ::
00450    *     A pointer to the first Bézier control point.
00451    *
00452    *   control2 ::
00453    *     A pointer to second Bézier control point.
00454    *
00455    *   to ::
00456    *     A pointer to the destination point.
00457    *
00458    * @return:
00459    *   FreeType error code.  0~means success.
00460    *
00461    * @note:
00462    *   You should call this function between @FT_Stroker_BeginSubPath and
00463    *   @FT_Stroker_EndSubPath.
00464    */
00465   FT_EXPORT( FT_Error )
00466   FT_Stroker_CubicTo( FT_Stroker  stroker,
00467                       FT_Vector*  control1,
00468                       FT_Vector*  control2,
00469                       FT_Vector*  to );
00470 
00471 
00472   /**************************************************************
00473    *
00474    * @function:
00475    *   FT_Stroker_GetBorderCounts
00476    *
00477    * @description:
00478    *   Call this function once you have finished parsing your paths
00479    *   with the stroker.  It returns the number of points and
00480    *   contours necessary to export one of the `border' or `stroke'
00481    *   outlines generated by the stroker.
00482    *
00483    * @input:
00484    *   stroker ::
00485    *     The target stroker handle.
00486    *
00487    *   border ::
00488    *     The border index.
00489    *
00490    * @output:
00491    *   anum_points ::
00492    *     The number of points.
00493    *
00494    *   anum_contours ::
00495    *     The number of contours.
00496    *
00497    * @return:
00498    *   FreeType error code.  0~means success.
00499    *
00500    * @note:
00501    *   When an outline, or a sub-path, is `closed', the stroker generates
00502    *   two independent `border' outlines, named `left' and `right'.
00503    *
00504    *   When the outline, or a sub-path, is `opened', the stroker merges
00505    *   the `border' outlines with caps.  The `left' border receives all
00506    *   points, while the `right' border becomes empty.
00507    *
00508    *   Use the function @FT_Stroker_GetCounts instead if you want to
00509    *   retrieve the counts associated to both borders.
00510    */
00511   FT_EXPORT( FT_Error )
00512   FT_Stroker_GetBorderCounts( FT_Stroker        stroker,
00513                               FT_StrokerBorder  border,
00514                               FT_UInt          *anum_points,
00515                               FT_UInt          *anum_contours );
00516 
00517 
00518   /**************************************************************
00519    *
00520    * @function:
00521    *   FT_Stroker_ExportBorder
00522    *
00523    * @description:
00524    *   Call this function after @FT_Stroker_GetBorderCounts to
00525    *   export the corresponding border to your own @FT_Outline
00526    *   structure.
00527    *
00528    *   Note that this function appends the border points and
00529    *   contours to your outline, but does not try to resize its
00530    *   arrays.
00531    *
00532    * @input:
00533    *   stroker ::
00534    *     The target stroker handle.
00535    *
00536    *   border ::
00537    *     The border index.
00538    *
00539    *   outline ::
00540    *     The target outline handle.
00541    *
00542    * @note:
00543    *   Always call this function after @FT_Stroker_GetBorderCounts to
00544    *   get sure that there is enough room in your @FT_Outline object to
00545    *   receive all new data.
00546    *
00547    *   When an outline, or a sub-path, is `closed', the stroker generates
00548    *   two independent `border' outlines, named `left' and `right'
00549    *
00550    *   When the outline, or a sub-path, is `opened', the stroker merges
00551    *   the `border' outlines with caps. The `left' border receives all
00552    *   points, while the `right' border becomes empty.
00553    *
00554    *   Use the function @FT_Stroker_Export instead if you want to
00555    *   retrieve all borders at once.
00556    */
00557   FT_EXPORT( void )
00558   FT_Stroker_ExportBorder( FT_Stroker        stroker,
00559                            FT_StrokerBorder  border,
00560                            FT_Outline*       outline );
00561 
00562 
00563   /**************************************************************
00564    *
00565    * @function:
00566    *   FT_Stroker_GetCounts
00567    *
00568    * @description:
00569    *   Call this function once you have finished parsing your paths
00570    *   with the stroker.  It returns the number of points and
00571    *   contours necessary to export all points/borders from the stroked
00572    *   outline/path.
00573    *
00574    * @input:
00575    *   stroker ::
00576    *     The target stroker handle.
00577    *
00578    * @output:
00579    *   anum_points ::
00580    *     The number of points.
00581    *
00582    *   anum_contours ::
00583    *     The number of contours.
00584    *
00585    * @return:
00586    *   FreeType error code.  0~means success.
00587    */
00588   FT_EXPORT( FT_Error )
00589   FT_Stroker_GetCounts( FT_Stroker  stroker,
00590                         FT_UInt    *anum_points,
00591                         FT_UInt    *anum_contours );
00592 
00593 
00594   /**************************************************************
00595    *
00596    * @function:
00597    *   FT_Stroker_Export
00598    *
00599    * @description:
00600    *   Call this function after @FT_Stroker_GetBorderCounts to
00601    *   export all borders to your own @FT_Outline structure.
00602    *
00603    *   Note that this function appends the border points and
00604    *   contours to your outline, but does not try to resize its
00605    *   arrays.
00606    *
00607    * @input:
00608    *   stroker ::
00609    *     The target stroker handle.
00610    *
00611    *   outline ::
00612    *     The target outline handle.
00613    */
00614   FT_EXPORT( void )
00615   FT_Stroker_Export( FT_Stroker   stroker,
00616                      FT_Outline*  outline );
00617 
00618 
00619   /**************************************************************
00620    *
00621    * @function:
00622    *   FT_Stroker_Done
00623    *
00624    * @description:
00625    *   Destroy a stroker object.
00626    *
00627    * @input:
00628    *   stroker ::
00629    *     A stroker handle.  Can be NULL.
00630    */
00631   FT_EXPORT( void )
00632   FT_Stroker_Done( FT_Stroker  stroker );
00633 
00634 
00635   /**************************************************************
00636    *
00637    * @function:
00638    *   FT_Glyph_Stroke
00639    *
00640    * @description:
00641    *   Stroke a given outline glyph object with a given stroker.
00642    *
00643    * @inout:
00644    *   pglyph ::
00645    *     Source glyph handle on input, new glyph handle on output.
00646    *
00647    * @input:
00648    *   stroker ::
00649    *     A stroker handle.
00650    *
00651    *   destroy ::
00652    *     A Boolean.  If~1, the source glyph object is destroyed
00653    *     on success.
00654    *
00655    * @return:
00656    *    FreeType error code.  0~means success.
00657    *
00658    * @note:
00659    *   The source glyph is untouched in case of error.
00660    */
00661   FT_EXPORT( FT_Error )
00662   FT_Glyph_Stroke( FT_Glyph    *pglyph,
00663                    FT_Stroker   stroker,
00664                    FT_Bool      destroy );
00665 
00666 
00667   /**************************************************************
00668    *
00669    * @function:
00670    *   FT_Glyph_StrokeBorder
00671    *
00672    * @description:
00673    *   Stroke a given outline glyph object with a given stroker, but
00674    *   only return either its inside or outside border.
00675    *
00676    * @inout:
00677    *   pglyph ::
00678    *     Source glyph handle on input, new glyph handle on output.
00679    *
00680    * @input:
00681    *   stroker ::
00682    *     A stroker handle.
00683    *
00684    *   inside ::
00685    *     A Boolean.  If~1, return the inside border, otherwise
00686    *     the outside border.
00687    *
00688    *   destroy ::
00689    *     A Boolean.  If~1, the source glyph object is destroyed
00690    *     on success.
00691    *
00692    * @return:
00693    *    FreeType error code.  0~means success.
00694    *
00695    * @note:
00696    *   The source glyph is untouched in case of error.
00697    */
00698   FT_EXPORT( FT_Error )
00699   FT_Glyph_StrokeBorder( FT_Glyph    *pglyph,
00700                          FT_Stroker   stroker,
00701                          FT_Bool      inside,
00702                          FT_Bool      destroy );
00703 
00704  /* */
00705 
00706 FT_END_HEADER
00707 
00708 #endif /* __FT_STROKE_H__ */
00709 
00710 
00711 /* END */
00712 
00713 
00714 /* Local Variables: */
00715 /* coding: utf-8    */
00716 /* End:             */

Generated on Tue Jul 5 14:13:38 2011 for ROOT_528-00b_version by  doxygen 1.5.1