Symbian3/PDK/Source/GUID-5A89E3C4-DEE7-5823-A109-92ED0D87B58C.dita
changeset 1 25a17d01db0c
child 3 46218c8b8afa
equal deleted inserted replaced
0:89d6a7a84779 1:25a17d01db0c
       
     1 <?xml version="1.0" encoding="utf-8"?>
       
     2 <!-- Copyright (c) 2007-2010 Nokia Corporation and/or its subsidiary(-ies) All rights reserved. -->
       
     3 <!-- This component and the accompanying materials are made available under the terms of the License 
       
     4 "Eclipse Public License v1.0" which accompanies this distribution, 
       
     5 and is available at the URL "http://www.eclipse.org/legal/epl-v10.html". -->
       
     6 <!-- Initial Contributors:
       
     7     Nokia Corporation - initial contribution.
       
     8 Contributors: 
       
     9 -->
       
    10 <!DOCTYPE concept
       
    11   PUBLIC "-//OASIS//DTD DITA Concept//EN" "concept.dtd">
       
    12 <concept id="GUID-5A89E3C4-DEE7-5823-A109-92ED0D87B58C" xml:lang="en"><title>Deriving
       
    13 from COpenFont</title><prolog><metadata><keywords/></metadata></prolog><conbody>
       
    14 <section><title>Overview</title> <p>Write a class derived from <codeph>COpenFont</codeph> to
       
    15 represent an instance of a typeface at a particular size, provide bitmaps
       
    16 of the glyphs, and determine whether a particular character is defined in
       
    17 the typeface. An object of this type is created by <codeph>COpenFontFile::GetNearestFontInPixelsL()</codeph> when
       
    18 it is called by the Font and Bitmap server. </p> <p>To derive from <codeph>COpenFont</codeph>: </p> <ul>
       
    19 <li id="GUID-855B3E95-D4FB-514D-9C9A-E325D4572F8B"><p>Write a function to
       
    20 construct the derived object on the shared heap. The base class constructor
       
    21 must be called when creating the derived object. </p> </li>
       
    22 <li id="GUID-1B4CA215-8150-580D-A9F2-3E7000A3317C"><p>Provide an implementation
       
    23 for <codeph>COpenFont</codeph>'s pure virtual function <codeph>RasterizeL()</codeph>. </p> </li>
       
    24 </ul> <p>These are discussed further in the following sections. </p> </section>
       
    25 <section><title>Construction using the shared heap </title> <p>The derived
       
    26 object must be created on a shared heap because it is shared by several processes,
       
    27 e.g. the Font and Bitmap Server and its clients. The following code fragment
       
    28 shows how the FreeType implementation creates the object on the shared heap <codeph>aHeap</codeph>: </p> <codeblock id="GUID-BF5816D4-8EFA-5A63-860F-F6F42A49914D" xml:space="preserve">CFreeTypeFont* CFreeTypeFont::NewL(RHeap* aHeap,
       
    29     COpenFontSessionCacheList* aSessionCacheList,
       
    30     CFreeTypeFontFile* aFontFile,TInt aSizeInPixels)
       
    31     {
       
    32     CFreeTypeFont* f =
       
    33         (CFreeTypeFont*)aHeap-&gt;AllocL(sizeof(CFreeTypeFont));
       
    34     new(f) CFreeTypeFont(aHeap,aSessionCacheList,aFontFile);
       
    35     CleanupStack::PushL(f);
       
    36     f-&gt;ConstructL(aSizeInPixels);
       
    37     CleanupStack::Pop();
       
    38     return f;
       
    39     }</codeblock> <p>Note that we use <codeph>aHeap-&gt;AllocL()</codeph> to
       
    40 obtain memory, then construct in place using a placement argument to <codeph>new</codeph>. </p> <p>The
       
    41 base class constructor is called when creating the derived object. Pass the
       
    42 arguments <codeph>aHeap</codeph> and <codeph>aSessionCacheList</codeph> supplied
       
    43 to <codeph>COpenFontFile::GetNearestFontInPixelsL()</codeph>, and pass the
       
    44 address of the <codeph>COpenFontFile</codeph> object that creates the <codeph>COpenFont</codeph> (i.e.,
       
    45 'this') as <codeph>aFile</codeph>. </p> </section>
       
    46 <section><title>Implementing RasterizeL()</title> <p>The derived class's <codeph>RasterizeL()</codeph> function
       
    47 is called by the Font and Bitmap Server to return the bitmap for a specified
       
    48 Unicode character. The function prototype is given below: </p> <codeblock id="GUID-806BC2E7-F34E-5809-BE79-56319147D77B" xml:space="preserve">virtual void RasterizeL(TInt aCode,TOpenFontGlyphData* aGlyphData) = 0;</codeblock> <p> Implementations
       
    49 must create a bitmap, in Symbian's run-length-encoded format, for the Unicode
       
    50 character <codeph>aCode</codeph>. The bitmap must be placed in <codeph>aGlyphData-&gt;iBitmapBuffer</codeph>,
       
    51 and the character metrics must be placed in <codeph>aGlyphData-&gt;iMetricsBuffer</codeph>.
       
    52 The other parts of <codeph>aGlyphData</codeph> should be left alone. </p> <p>The
       
    53 actual rasterization task should be passed to the rasterization engine. One
       
    54 way of doing this is to call some rasterization member function of the <codeph>COpenFontFile</codeph> object,
       
    55 to which a pointer can be obtained by calling <codeph>COpenFont::File()</codeph>.
       
    56 The derived <codeph>COpenFontFile</codeph> object can then call a rasterizer
       
    57 function via a pointer it owns to the rasterizer context object. Note that <i>if</i> the
       
    58 rasterizer context object is derived from <codeph>COpenFontRasterizerContext</codeph>,
       
    59 it will have utility functions for writing bits to the bitmap buffer in Symbian's
       
    60 run-length-encoded format. </p> <p>The FreeType implementation follows this
       
    61 strategy. <codeph>CFreeTypeFont::RasterizeL()</codeph> calls <codeph>CFreeTypeFontFile::RasterizeL()</codeph>,
       
    62 which calls <codeph>CFreeTypeContext::RasterizeL()</codeph>. </p> <p><b>The
       
    63 run-length-encoded bitmap format</b> </p> <p>The run-length-encoded format
       
    64 is a packed binary format starting on a byte boundary and made up of a number
       
    65 of sections. </p> <p>Each section starts with a five-bit header. If the first
       
    66 bit of the header is 0 the next four bits are a repeat count, starting with
       
    67 the least significant bit, and a single row of bits follows (the number of
       
    68 bits in a row is specified by <codeph>aGlyphData-&gt;iMetricsBuffer.Width()</codeph>).
       
    69 If the first bit of the header is 1 the next four bits are a count of non-repeating
       
    70 rows, again starting with the least significant bit, and that many rows of
       
    71 bits follow. </p> <p>See <xref href="GUID-F44D974F-AADE-5E6C-8D69-8D3EEE4BD395.dita">How
       
    72 to derive from COpenFontRasterizerContext</xref> for an implementation of
       
    73 this algorithm. </p> </section>
       
    74 </conbody><related-links>
       
    75 <link href="GUID-F477E82D-2929-5C69-BF6D-A69A61AC9EA5.dita"><linktext>Creating
       
    76 a Font Rasterizer Plug-in</linktext></link>
       
    77 <link href="GUID-1CF78E25-8C83-5812-AE6F-8612B3F9CDA9.dita"><linktext>Deriving
       
    78 from COpenFontRasterizer</linktext></link>
       
    79 <link href="GUID-BCF6FEF0-1792-5DEA-A2D7-896E47163547.dita"><linktext>Deriving
       
    80 from COpenFontFile</linktext></link>
       
    81 <link href="GUID-F44D974F-AADE-5E6C-8D69-8D3EEE4BD395.dita"><linktext>Deriving
       
    82 from COpenFontRasterizerContext</linktext></link>
       
    83 </related-links></concept>