vtk-m/vtkm/rendering/BitmapFont.h

119 lines
2.6 KiB
C
Raw Normal View History

2019-04-15 23:24:21 +00:00
//============================================================================
// 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.
2019-04-15 23:24:21 +00:00
//============================================================================
#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>
2017-05-18 14:29:41 +00:00
namespace vtkm
{
namespace rendering
{
class VTKM_RENDERING_EXPORT BitmapFont
{
public:
struct Character
{
std::string id;
2017-05-18 14:29:41 +00:00
char c;
int offx, offy;
int x, y, w, h;
int adv;
int kern[256];
2017-05-18 14:29:41 +00:00
Character() { ResetKerning(); }
Character(const std::string& id_,
char c_,
int offx_,
int offy_,
int x_,
int y_,
int w_,
int h_,
2017-05-18 14:29:41 +00:00
int adv_)
: id(id_)
, c(c_)
, offx(offx_)
, offy(offy_)
, x(x_)
, y(y_)
, w(w_)
, h(h_)
, adv(adv_)
{
ResetKerning();
}
2017-05-18 14:29:41 +00:00
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()
{
2017-05-18 14:29:41 +00:00
for (int i = 0; i < 256; i++)
2016-08-26 19:30:52 +00:00
{
2017-05-18 14:29:41 +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;
2017-05-18 14:29:41 +00:00
int Height;
int Ascender;
int Descender;
int ImgW, ImgH;
int PadL, PadR, PadT, PadB;
int ShortMap[256];
2016-06-01 17:37:03 +00:00
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();
2017-05-18 14:29:41 +00:00
const Character& GetChar(char c) const;
2016-08-26 19:30:52 +00:00
VTKM_CONT
2017-05-18 14:29:41 +00:00
const std::vector<unsigned char>& GetRawImageData() const { return this->RawImageFileData; }
2017-05-18 14:29:41 +00:00
vtkm::Float32 GetTextWidth(const std::string& text) const;
2016-08-26 19:30:52 +00:00
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;
};
2017-05-18 14:29:41 +00:00
}
} //namespace vtkm::rendering
#endif