zoukankan      html  css  js  c++  java
  • Font: a C++ class

    Font: a C++ class
            
    This class is used in

        Fractal Generator.
        Avi Examples

    The header file
    Font.h

    /*
       Font.h

       Copyright (C) 2002-2005 René Nyffenegger

       This source code is provided 'as-is', without any express or implied
       warranty. In no event will the author be held liable for any damages
       arising from the use of this software.

       Permission is granted to anyone to use this software for any purpose,
       including commercial applications, and to alter it and redistribute it
       freely, subject to the following restrictions:

       1. The origin of this source code must not be misrepresented; you must not
          claim that you wrote the original source code. If you use this source code
          in a product, an acknowledgment in the product documentation would be
          appreciated but is not required.

       2. Altered source versions must be plainly marked as such, and must not be
          misrepresented as being the original source code.

       3. This notice may not be removed or altered from any source distribution.

       René Nyffenegger rene.nyffenegger@adp-gmbh.ch
    */

    #ifndef FONT_H_
    #define FONT_H_

    #include <string>
    #include <sstream>
    #include <windows.h>

    #include "STD_STR.h"

    class Font {

      public:
      Font(STD_STR const& name, int size=12, bool bold=false, bool italic=false, bool underlined=false);

     ~Font();

      protected:
        friend class DC;
        Font(HFONT f) : font_(f){};
        operator HFONT() const {return font_;};

      private:
        HFONT font_;
    };

    #endif

    The implementation file
    Font.cpp

    /*
       Font.cpp

       Copyright (C) 2002-2004 René Nyffenegger

       This source code is provided 'as-is', without any express or implied
       warranty. In no event will the author be held liable for any damages
       arising from the use of this software.

       Permission is granted to anyone to use this software for any purpose,
       including commercial applications, and to alter it and redistribute it
       freely, subject to the following restrictions:

       1. The origin of this source code must not be misrepresented; you must not
          claim that you wrote the original source code. If you use this source code
          in a product, an acknowledgment in the product documentation would be
          appreciated but is not required.

       2. Altered source versions must be plainly marked as such, and must not be
          misrepresented as being the original source code.

       3. This notice may not be removed or altered from any source distribution.

       René Nyffenegger rene.nyffenegger@adp-gmbh.ch
    */

    #include "Font.h"

    Font::Font(STD_STR const& name, int size, bool bold, bool italic, bool underlined) {
      font_ = ::CreateFont(size, 0, 0, 0, bold? FW_BOLD : FW_NORMAL, italic, underlined, false,
          DEFAULT_CHARSET,
          OUT_DEFAULT_PRECIS,
          CLIP_DEFAULT_PRECIS,
          DEFAULT_QUALITY,
          FF_DONTCARE,
          name.c_str());

      if (!font_) {
        throw "Couldn't create font";
      }
    }

    Font::~Font() {
      ::DeleteObject(font_);
    }

  • 相关阅读:
    [daily][troubleshoot][archlinux][wps][font] wps文档中的图内容无法显示中文
    [troubleshoot][daily][archlinux][pacman] pacman 与 pip 包文件冲突
    [daily] 宇宙终极shell之zsh
    [knowledge][basic][hardware] 内存的硬件结构(转)
    [troubleshoot][archlinux][X] GPU HANG
    [daily]使用rdtsc指令,测量程序的运行速度 [转]
    [have_fun] 好玩哒小游戏又来啦
    [dpdk] 读开发指南(2)(内容长期整理中)
    [Virtualization][SDN] 讲的很好的SDN软件定义网络视频课程
    [Virtualization][SDN] VXLAN到底是什么 [转]
  • 原文地址:https://www.cnblogs.com/honeynm/p/4695864.html
Copyright © 2011-2022 走看看