glfont.cpp
上传用户:yhdzpy8989
上传日期:2007-06-13
资源大小:13604k
文件大小:6k
- /*
- * ===========================================================================
- * PRODUCTION $Log: glfont.cpp,v $
- * PRODUCTION Revision 1000.1 2004/06/01 20:50:53 gouriano
- * PRODUCTION PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.13
- * PRODUCTION
- * ===========================================================================
- */
- /* $Id: glfont.cpp,v 1000.1 2004/06/01 20:50:53 gouriano Exp $
- * ===========================================================================
- *
- * PUBLIC DOMAIN NOTICE
- * National Center for Biotechnology Information
- *
- * This software / database is a "United States Government Work" under the
- * terms of the United States Copyright Act. It was written as part of
- * the author's official duties as a United States Government employee and
- * thus cannot be copyrighted. This software / database is freely available
- * to the public for use. The National Library of Medicine and the U.S.
- * Government have not placed any restriction on its use or reproduction.
- *
- * Although all reasonable efforts have been taken to ensure the accuracy
- * and reliability of the software and data, the NLM and the U.S.
- * Government do not and cannot warrant the performance or results that
- * may be obtained by using this software or data. The NLM and the U.S.
- * Government disclaim all warranties, express or implied, including
- * warranties of performance, merchantability or fitness for any particular
- * purpose.
- *
- * Please cite the author in any work or product based on this material.
- *
- * ===========================================================================
- *
- * Authors: Mike DiCuccio
- *
- * File Description:
- * CGlutFont -- GLUT based bitmap fonts
- */
- #include <ncbi_pch.hpp>
- #include <gui/opengl.h>
- #include <gui/opengl/glfont.hpp>
- #include <math.h>
- BEGIN_NCBI_SCOPE
- //
- // text block
- //
- // size:
- // 1 for begin token
- // 1 for size
- // 1 for text length
- // 5 for position (token + 4 floats)
- // 5 for color (token + 4 floats)
- // N for text
- // 1 for end token
- //
- static const size_t s_TEXTBLOCK_SIZE = 14;
- vector<float> CGlFeedbackFont::EncodeText(GLfloat pos[4],
- const CGlColor& color,
- const char* text,
- size_t length)
- {
- vector<float> vec;
- vec.push_back(eBeginText);
- const size_t size = size_t(s_TEXTBLOCK_SIZE + ceil(double(length) / 4));
- vec.push_back(float(size));
- vec.push_back(float(length));
- vec.push_back(ePosition);
- for (int i = 0; i < 4; ++i) {
- vec.push_back(pos[i]);
- }
- vec.push_back(eColor);
- const GLfloat* c = color.GetGlColor();
- for (int i = 0; i < 4; ++i) {
- vec.push_back(c[i]);
- }
- const char* textptr = text;
- for (size_t i = 0; i < length; ) {
- union FPackChar fpc = { 0 };
- for (size_t j = 0; j < 4 && i < length; ++j, ++i, ++textptr) {
- fpc.c[j] = *textptr;
- }
- vec.push_back(fpc.f);
- }
- vec.push_back(eEndText);
- return vec;
- }
- vector<float> CGlFeedbackFont::EncodeText(GLfloat pos[4],
- const CGlColor& color,
- const string& text)
- {
- return EncodeText(pos, color, text.data(), text.size());
- }
- void CGlFeedbackFont::DecodeText(const vector<float>& textbuf,
- GLfloat* pos,
- GLfloat* color,
- string& text)
- {
- vector<float>::const_iterator it = textbuf.begin();
- if (*it != eBeginText) {
- LOG_POST(Info << "expecting BEGIN_TEXT token");
- return;
- }
- const size_t size = size_t(*++it);
- const size_t textlen = size_t(*++it);
- text.erase();
- // reserve a little more than needed
- text.reserve(textlen + 10);
- if (*++it != ePosition) {
- LOG_POST(Info << "expecting POSITION token");
- return;
- }
- for (int i = 0; i < 4; ++i) {
- pos[i] = *++it;
- }
- if (*++it != eColor) {
- LOG_POST(Info << "expecting COLOR token");
- return;
- }
- for (int i = 0; i < 4; ++i) {
- color[i] = *++it;
- }
- vector<float>::const_iterator end = textbuf.end() - 1;
- if (*end != eEndText) {
- LOG_POST(Info << "expecting END_TEXT token at end of text");
- return;
- }
- // i needs to be a signed type
- for (int i = int(textlen); i > 0 && it != end; i -= 4) {
- union FPackChar fpc = { *++it };
- text.append((const char*) &fpc.c, i < 4 ? i : 4);
- }
- }
- END_NCBI_SCOPE
- /*
- * ===========================================================================
- * $Log: glfont.cpp,v $
- * Revision 1000.1 2004/06/01 20:50:53 gouriano
- * PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.13
- *
- * Revision 1.13 2004/05/21 22:27:45 gorelenk
- * Added PCH ncbi_pch.hpp
- *
- * Revision 1.12 2003/09/17 16:26:13 dicuccio
- * Removed CGlutFont
- *
- * Revision 1.11 2003/08/28 19:27:54 dicuccio
- * TextOut() functions are now const
- *
- * Revision 1.10 2003/08/22 15:47:12 dicuccio
- * Added display lists to CGlBitmapFont
- *
- * Revision 1.9 2003/08/18 19:23:55 dicuccio
- * Changed API of IGlFont and CGlutFont - return float from TextWidth() and
- * TextHeight
- *
- * Revision 1.8 2003/06/24 19:17:57 meric
- * Fix OpenGL feedback mechanism for text - add text length, fix DecodeText()
- *
- * Revision 1.7 2003/05/30 13:00:36 dicuccio
- * Remove compiler warnings about signed / unsigend comparisons
- *
- * Revision 1.6 2003/05/13 22:06:50 meric
- * Replace static constants with enums
- *
- * Revision 1.5 2003/05/13 19:27:38 dicuccio
- * Added CGlFeedbackFont; added support for font encoding for converting bitmap ->
- * vector fonts (Peter Meric)
- *
- * Revision 1.4 2003/01/13 13:10:11 dicuccio
- * Namespace clean-up. Retired namespace gui -> converted all to namespace ncbi.
- * Moved all FLUID-generated code into namespace ncbi.
- *
- * Revision 1.3 2002/11/14 16:24:44 dicuccio
- * Changed to include standard OpenGL headers through 'gui/opengl.h'
- *
- * Revision 1.2 2002/11/08 13:27:45 dicuccio
- * Code clean-up and reformatting.
- *
- * Revision 1.1 2002/11/05 20:21:47 dicuccio
- * Initial revision
- *
- * ===========================================================================
- */