pleyo.com

/src/trunk2/BAL/Interfaces/font/GlyphWidthMap.h

Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2006 Apple Computer, Inc.  All rights reserved.
00003  *
00004  * Redistribution and use in source and binary forms, with or without
00005  * modification, are permitted provided that the following conditions
00006  * are met:
00007  *
00008  * 1.  Redistributions of source code must retain the above copyright
00009  *     notice, this list of conditions and the following disclaimer. 
00010  * 2.  Redistributions in binary form must reproduce the above copyright
00011  *     notice, this list of conditions and the following disclaimer in the
00012  *     documentation and/or other materials provided with the distribution. 
00013  * 3.  Neither the name of Apple Computer, Inc. ("Apple") nor the names of
00014  *     its contributors may be used to endorse or promote products derived
00015  *     from this software without specific prior written permission. 
00016  *
00017  * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
00018  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
00019  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00020  * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
00021  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
00022  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00023  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
00024  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00025  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
00026  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00027  */
00028 
00029 #ifndef GlyphWidthMap_h
00030 #define GlyphWidthMap_h
00031 
00032 #include <wtf/unicode/Unicode.h>
00033 #include <wtf/Noncopyable.h>
00034 #include <wtf/HashMap.h>
00035 
00036 namespace WebCore {
00037 
00038 typedef unsigned short Glyph;
00039 
00040 const float cGlyphWidthUnknown = -1;
00041 
00042 class GlyphWidthMap : Noncopyable {
00043 public:
00044     GlyphWidthMap() : m_filledPrimaryPage(false), m_pages(0) {}
00045     ~GlyphWidthMap() { if (m_pages) { deleteAllValues(*m_pages); delete m_pages; } }
00046 
00047     float widthForGlyph(Glyph);
00048     void setWidthForGlyph(Glyph, float);
00049 
00050 private:
00051     struct GlyphWidthPage {
00052         static const size_t size = 256; // Usually covers Latin-1 in a single page.
00053         float m_widths[size];
00054 
00055         float widthForGlyph(Glyph g) const { return m_widths[g % size]; }
00056         void setWidthForGlyph(Glyph g, float w)
00057         {
00058             setWidthForIndex(g % size, w);
00059         }
00060         void setWidthForIndex(unsigned index, float w)
00061         {
00062             m_widths[index] = w;
00063         }
00064     };
00065     
00066     GlyphWidthPage* locatePage(unsigned page);
00067     
00068     bool m_filledPrimaryPage;
00069     GlyphWidthPage m_primaryPage; // We optimize for the page that contains glyph indices 0-255.
00070     HashMap<int, GlyphWidthPage*>* m_pages;
00071 };
00072 
00073 }
00074 #endif

Generated on Wed Nov 21 20:04:17 2007 for Origyn Web Browser by Doxygen 1.5.3

pleyo.com
pleyo.com