vtk-m/vtkm/rendering/BitmapFont.h

107 lines
2.8 KiB
C
Raw Normal View History

//=============================================================================
//
// Copyright (c) Kitware, Inc.
// All rights reserved.
// See LICENSE.txt for details.
//
// This software is distributed WITHOUT ANY WARRANTY; without even
// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
// PURPOSE. See the above copyright notice for more information.
//
// Copyright 2015 Sandia Corporation.
// Copyright 2015 UT-Battelle, LLC.
// Copyright 2015 Los Alamos National Security.
//
// Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
// the U.S. Government retains certain rights in this software.
// Under the terms of Contract DE-AC52-06NA25396 with Los Alamos National
// Laboratory (LANL), the U.S. Government retains certain rights in
// this software.
//
//=============================================================================
#ifndef vtk_m_BitmapFont_h
#define vtk_m_BitmapFont_h
2016-08-26 19:30:52 +00:00
#include <vtkm/rendering/vtkm_rendering_export.h>
#include <vtkm/Types.h>
#include <string>
#include <vector>
namespace vtkm {
namespace rendering {
class VTKM_RENDERING_EXPORT BitmapFont
{
public:
struct Character
{
std::string id;
char c;
int offx, offy;
int x, y, w, h;
int adv;
int kern[256];
Character()
{
ResetKerning();
}
Character(const std::string &id_, char c_, int offx_, int offy_,
int x_, int y_, int w_, int h_, int adv_)
: id(id_), c(c_), offx(offx_), offy(offy_),
x(x_), y(y_), w(w_), h(h_), adv(adv_)
{
ResetKerning();
}
Character(const std::string &id_, const int metrics[])
: id(id_), c((char)metrics[0]), offx(metrics[1]), offy(metrics[2]),
x(metrics[3]), y(metrics[4]), w(metrics[5]), h(metrics[6]),
adv(metrics[7])
{
ResetKerning();
}
void ResetKerning()
{
for (int i=0; i<256; i++)
2016-08-26 19:30:52 +00:00
{
kern[i]=0;
2016-08-26 19:30:52 +00:00
}
}
};
2016-06-01 17:37:03 +00:00
std::string Name;
std::string ImageFile;
int Height;
int Ascender;
int Descender;
int ImgW, ImgH;
int PadL, PadR, PadT, PadB;
int ShortMap[256];
std::vector<Character> Chars;
2016-06-01 17:37:03 +00:00
std::vector<unsigned char> RawImageFileData;
public:
2016-08-26 19:30:52 +00:00
BitmapFont();
const Character &GetChar(char c) const;
VTKM_CONT_EXPORT
const std::vector<unsigned char> &GetRawImageData() const
{
2016-06-01 17:37:03 +00:00
return this->RawImageFileData;
}
2016-08-26 19:30:52 +00:00
vtkm::Float32 GetTextWidth(const std::string &text) const;
void GetCharPolygon(char character, vtkm::Float32 &x, vtkm::Float32 &y,
vtkm::Float32 &vl, vtkm::Float32 &vr, vtkm::Float32 &vt, vtkm::Float32 &vb,
vtkm::Float32 &tl, vtkm::Float32 &tr, vtkm::Float32 &tt, vtkm::Float32 &tb,
2016-08-26 19:30:52 +00:00
char nextchar = 0) const;
};
}} //namespace vtkm::rendering
#endif