Back to index

nux  3.0.0
Public Member Functions | Private Attributes
nux::EMMetrics Class Reference

#include <EMMetrics.h>

List of all members.

Public Member Functions

 EMMetrics (Display *dpy, int scr, double points)
double Pixel2EM (int value)
int EM2Pixel (double value)

Private Attributes

double pixels_per_em_

Detailed Description

Definition at line 26 of file EMMetrics.h.


Constructor & Destructor Documentation

nux::EMMetrics::EMMetrics ( Display *  dpy,
int  scr,
double  points 
)

Definition at line 23 of file EMMetrics.cpp.

  {
    double xres = 0.0;
    double yres = 0.0;
    double dpi  = 96.0; // default DPI if no Display provided (e.g. unit-test)

    if (dpy)
    {
      // determine current system DPI, remember that: 1 inch == 2.54 cm == 25.4 mm
      xres = ((static_cast<double> DisplayWidth(dpy,scr) * 25.4) /
              (static_cast<double> DisplayWidthMM(dpy,scr)));
      yres = ((static_cast<double> DisplayHeight(dpy,scr) * 25.4) /
              (static_cast<double> DisplayHeightMM(dpy,scr)));
      dpi = (xres + yres) / 2.0; 
    }

    // update stored ppe
    pixels_per_em_ = points * dpi / 72.0;

    // sanity-check
    if (pixels_per_em_ == 0.0)
      pixels_per_em_ = 10.0; // assume points == 10.0, dpi == 96.0
  }

Member Function Documentation

int nux::EMMetrics::EM2Pixel ( double  value)

Definition at line 52 of file EMMetrics.cpp.

  {
    return static_cast<int> (value * pixels_per_em_);
  }
double nux::EMMetrics::Pixel2EM ( int  value)

Definition at line 47 of file EMMetrics.cpp.

  {
    return static_cast<double> (value) / pixels_per_em_;
  }

Member Data Documentation

Definition at line 35 of file EMMetrics.h.


The documentation for this class was generated from the following files: