Select Git revision
Forked from
gmsh / gmsh
Source project has a limited visibility.
-
Gaetan Bricteux authoredGaetan Bricteux authored
drawGlyph.cpp 18.62 KiB
// Gmsh - Copyright (C) 1997-2010 C. Geuzaine, J.-F. Remacle
//
// See the LICENSE.txt file for license information. Please report all
// bugs and problems to <gmsh@geuz.org>.
#include <string.h>
#include "drawContext.h"
#include "GmshDefines.h"
#include "Numeric.h"
#include "StringUtils.h"
#include "Context.h"
#include "gl2ps.h"
#include "SVector3.h"
void drawContext::drawString(const std::string &s, const std::string &font_name,
int font_enum, int font_size, int align)
{
if(CTX::instance()->printing && !CTX::instance()->print.text) return;
// change the raster position only if not creating TeX files
if(align > 0 && (!CTX::instance()->printing ||
CTX::instance()->print.format != FORMAT_TEX)){
GLboolean valid;
glGetBooleanv(GL_CURRENT_RASTER_POSITION_VALID, &valid);
if(valid == GL_TRUE){
GLdouble pos[4];
glGetDoublev(GL_CURRENT_RASTER_POSITION, pos);
double x[3], w[3] = {pos[0], pos[1], pos[2]};
drawContext::global()->setFont(font_enum, font_size);
double width = drawContext::global()->getStringWidth(s.c_str());
double height = drawContext::global()->getStringHeight();
switch(align){
case 1: w[0] -= width/2.; break; // bottom center
case 2: w[0] -= width; break; // bottom right
case 3: w[1] -= height; break; // top left
case 4: w[0] -= width/2.; w[1] -= height; break; // top center
case 5: w[0] -= width; w[1] -= height; break; // top right
case 6: w[1] -= height/2.; break; // center left
case 7: w[0] -= width/2.; w[1] -= height/2.; break; // center center
case 8: w[0] -= width; w[1] -= height/2.; break; // center right
default: break;
}
viewport2World(w, x);
glRasterPos3d(x[0], x[1], x[2]);
}
}
if(!CTX::instance()->printing){
drawContext::global()->setFont(font_enum, font_size);
drawContext::global()->drawString(s.c_str());
}
else{
if(CTX::instance()->print.format == FORMAT_TEX){
std::string tmp = SanitizeTeXString
(s.c_str(), CTX::instance()->print.texAsEquation);
int opt;
switch(align){
case 1: opt = GL2PS_TEXT_B; break; // bottom center
case 2: opt = GL2PS_TEXT_BR; break; // bottom right
case 3: opt = GL2PS_TEXT_TL; break; // top left
case 4: opt = GL2PS_TEXT_T; break; // top center
case 5: opt = GL2PS_TEXT_TR; break; // top right
case 6: opt = GL2PS_TEXT_CL; break; // center left
case 7: opt = GL2PS_TEXT_C; break; // center center
case 8: opt = GL2PS_TEXT_CR; break; // center right
default: opt = GL2PS_TEXT_BL; break; // bottom left
}
gl2psTextOpt(tmp.c_str(), font_name.c_str(), font_size, opt, 0.);
}
else if(CTX::instance()->print.epsQuality &&