Add THE_DEFAULT_RESOLUTION static const parameter to Graphic3d_RenderingParams.
Add resolution to Graphic3d_RenderingParams.
Drop redundant variables from OpenGl_Workspace.
Add a new parameter to Graphic3d_GraphicDriver::TextSize method (and to OpenGl_GraphicDriver).
Add a new parameter to OpenGl_Text::Render() and to OpenGl_Text::render() methods.
OpenGl_Text::FontKey() considers a resolution (PPI) now.
Add a new argument '-resolution' (sets a pixel density) in the 'VRenderParams' draw-command.
//=======================================================================
void AIS_ColorScale::TextSize (const TCollection_ExtendedString& theText, const Standard_Integer theHeight, Standard_Integer& theWidth, Standard_Integer& theAscent, Standard_Integer& theDescent) const
{
+ const Handle(Graphic3d_CView)& aView = GetContext()->CurrentViewer()->ActiveView()->View();
Standard_ShortReal aWidth(10.0), anAscent(1.0), aDescent(1.0);
TCollection_AsciiString aText (theText.ToExtString(), '?');
- GetContext()->CurrentViewer()->Driver()->TextSize (aText.ToCString(),(Standard_ShortReal)theHeight,aWidth,anAscent,aDescent);
+ GetContext()->CurrentViewer()->Driver()->TextSize (aView, aText.ToCString(), (Standard_ShortReal)theHeight, aWidth, anAscent, aDescent);
theWidth = (Standard_Integer)aWidth;
theAscent = (Standard_Integer)anAscent;
theDescent = (Standard_Integer)aDescent;
//! @return true on success
Standard_EXPORT bool Init (const NCollection_String& theFontPath,
const unsigned int thePointSize,
- const unsigned int theResolution = 72);
+ const unsigned int theResolution);
//! Initialize the font.
//! @param theFontName the font name
virtual Standard_ShortReal DefaultTextHeight() const = 0;
- //! call_togl_textsize2d
- virtual void TextSize (const Standard_CString AText, const Standard_ShortReal AHeight, Standard_ShortReal& AWidth, Standard_ShortReal& AnAscent, Standard_ShortReal& ADescent) const = 0;
+ //! Computes text width.
+ virtual void TextSize (const Handle(Graphic3d_CView)& theView,
+ const Standard_CString theText,
+ const Standard_ShortReal theHeight,
+ Standard_ShortReal& theWidth,
+ Standard_ShortReal& theAscent,
+ Standard_ShortReal& theDescent) const = 0;
//! Add a new top-level z layer with ID <theLayerId> for
//! the view. Z layers allow drawing structures in higher layers
class Graphic3d_RenderingParams
{
public:
+ //! Default pixels density.
+ static const unsigned int THE_DEFAULT_RESOLUTION = 72u;
//! Default number of samples per pixel.
static const Standard_Integer THE_DEFAULT_SPP = 1;
StereoMode (Graphic3d_StereoMode_QuadBuffer),
AnaglyphFilter (Anaglyph_RedCyan_Optimized),
- ToReverseStereo (Standard_False)
+ ToReverseStereo (Standard_False),
+
+ Resolution (THE_DEFAULT_RESOLUTION)
{
const Graphic3d_Vec4 aZero (0.0f, 0.0f, 0.0f, 0.0f);
AnaglyphLeft .SetRow (0, Graphic3d_Vec4 (1.0f, 0.0f, 0.0f, 0.0f));
Graphic3d_Mat4 AnaglyphRight; //!< right anaglyph filter (in normalized colorspace), Color = AnaglyphRight * theColorRight + AnaglyphLeft * theColorLeft;
Standard_Boolean ToReverseStereo; //!< flag to reverse stereo pair, FALSE by default
+ unsigned int Resolution; //!< Pixels density (PPI), defines scaling factor for parameters like text size
+ //!< (when defined in screen-space units rather than in 3D) to be properly displayed
+ //!< on device (screen / printer). 72 is default value.
+ //!< Note that using difference resolution in different Views in same Viewer
+ //!< will lead to performance regression (for example, text will be recreated every time).
+
};
#endif // _Graphic3d_RenderingParams_HeaderFile
// function : TextSize
// purpose :
// =======================================================================
-void OpenGl_GraphicDriver::TextSize (const Standard_CString theText,
- const Standard_ShortReal theHeight,
- Standard_ShortReal& theWidth,
- Standard_ShortReal& theAscent,
- Standard_ShortReal& theDescent) const
+void OpenGl_GraphicDriver::TextSize (const Handle(Graphic3d_CView)& theView,
+ const Standard_CString theText,
+ const Standard_ShortReal theHeight,
+ Standard_ShortReal& theWidth,
+ Standard_ShortReal& theAscent,
+ Standard_ShortReal& theDescent) const
{
const Handle(OpenGl_Context)& aCtx = GetSharedContext();
if (aCtx.IsNull())
aTextAspect.SetAspect(aDefaultContextText);
TCollection_ExtendedString anExtText = theText;
NCollection_String aText = (Standard_Utf16Char* )anExtText.ToExtString();
- OpenGl_Text::StringSize (aCtx, aText, aTextAspect, aTextParam, theWidth, theAscent, theDescent);
+ OpenGl_Text::StringSize(aCtx, aText, aTextAspect, aTextParam, theView->RenderingParams().Resolution, theWidth, theAscent, theDescent);
}
//=======================================================================
public:
- Standard_EXPORT void TextSize (const Standard_CString AText,const Standard_ShortReal AHeight,Standard_ShortReal& AWidth,Standard_ShortReal& AnAscent,Standard_ShortReal& ADescent) const;
+ Standard_EXPORT void TextSize (const Handle(Graphic3d_CView)& theView,
+ const Standard_CString theText,
+ const Standard_ShortReal theHeight,
+ Standard_ShortReal& theWidth,
+ Standard_ShortReal& theAscent,
+ Standard_ShortReal& theDescent) const;
Standard_EXPORT Standard_Integer InquirePlaneLimit();
const NCollection_String& theText,
const OpenGl_AspectText& theTextAspect,
const OpenGl_TextParam& theParams,
+ const unsigned int theResolution,
Standard_ShortReal& theWidth,
Standard_ShortReal& theAscent,
Standard_ShortReal& theDescent)
theWidth = 0.0f;
theAscent = 0.0f;
theDescent = 0.0f;
- const TCollection_AsciiString aFontKey = FontKey (theTextAspect, theParams.Height);
- Handle(OpenGl_Font) aFont = FindFont (theCtx, theTextAspect, theParams.Height, aFontKey);
+ const TCollection_AsciiString aFontKey = FontKey (theTextAspect, theParams.Height, theResolution);
+ Handle(OpenGl_Font) aFont = FindFont (theCtx, theTextAspect, theParams.Height, theResolution, aFontKey);
if (aFont.IsNull() || !aFont->IsValid())
{
return;
aCtx,
*aTextAspect,
*theWorkspace->HighlightColor,
- *theWorkspace->HighlightColor);
+ *theWorkspace->HighlightColor,
+ theWorkspace->View()->RenderingParams().Resolution);
}
else
{
aCtx,
*aTextAspect,
aTextAspect->Color(),
- aTextAspect->SubtitleColor());
+ aTextAspect->SubtitleColor(),
+ theWorkspace->View()->RenderingParams().Resolution);
}
aCtx->BindProgram (NULL);
// =======================================================================
void OpenGl_Text::Render (const Handle(OpenGl_PrinterContext)& thePrintCtx,
const Handle(OpenGl_Context)& theCtx,
- const OpenGl_AspectText& theTextAspect) const
+ const OpenGl_AspectText& theTextAspect,
+ const unsigned int theResolution) const
{
- render (thePrintCtx, theCtx, theTextAspect, theTextAspect.Color(), theTextAspect.SubtitleColor());
+ render (thePrintCtx, theCtx, theTextAspect, theTextAspect.Color(), theTextAspect.SubtitleColor(), theResolution);
}
// =======================================================================
// purpose :
// =======================================================================
TCollection_AsciiString OpenGl_Text::FontKey (const OpenGl_AspectText& theAspect,
- const Standard_Integer theHeight)
+ const Standard_Integer theHeight,
+ const unsigned int theResolution)
{
const Font_FontAspect anAspect = (theAspect.FontAspect() != Font_FA_Undefined) ? theAspect.FontAspect() : Font_FA_Regular;
return theAspect.FontName()
+ TCollection_AsciiString(":") + Standard_Integer(anAspect)
+ + TCollection_AsciiString(":") + Standard_Integer(theResolution)
+ TCollection_AsciiString(":") + theHeight;
}
Handle(OpenGl_Font) OpenGl_Text::FindFont (const Handle(OpenGl_Context)& theCtx,
const OpenGl_AspectText& theAspect,
const Standard_Integer theHeight,
+ const unsigned int theResolution,
const TCollection_AsciiString theKey)
{
Handle(OpenGl_Font) aFont;
{
aFontFt = new Font_FTFont (NULL);
- if (aFontFt->Init (aRequestedFont->FontPath()->ToCString(), theHeight))
+ if (aFontFt->Init (aRequestedFont->FontPath()->ToCString(), theHeight, theResolution))
{
aFont = new OpenGl_Font (aFontFt, theKey);
if (!aFont->Init (theCtx))
const Handle(OpenGl_Context)& theCtx,
const OpenGl_AspectText& theTextAspect,
const TEL_COLOUR& theColorText,
- const TEL_COLOUR& theColorSubs) const
+ const TEL_COLOUR& theColorSubs,
+ const unsigned int theResolution) const
{
if (myString.IsEmpty())
{
return;
}
- const TCollection_AsciiString aFontKey = FontKey (theTextAspect, myParams.Height);
+ // Note that using difference resolution in different Views in same Viewer
+ // will lead to performance regression (for example, text will be recreated every time).
+ const TCollection_AsciiString aFontKey = FontKey (theTextAspect, myParams.Height, theResolution);
if (!myFont.IsNull()
&& !myFont->ResourceKey().IsEqual (aFontKey))
{
if (myFont.IsNull())
{
- myFont = FindFont (theCtx, theTextAspect, myParams.Height, aFontKey);
+ myFont = FindFont (theCtx, theTextAspect, myParams.Height, theResolution, aFontKey);
}
if (!myFont->WasInitialized())
{
#include <TCollection_ExtendedString.hxx>
#include <Graphic3d_Vertex.hxx>
#include <Graphic3d_HorizontalTextAlignment.hxx>
+#include <Graphic3d_RenderingParams.hxx>
#include <Graphic3d_VerticalTextAlignment.hxx>
#include <gp_Ax2.hxx>
//! Create key for shared resource
Standard_EXPORT static TCollection_AsciiString FontKey (const OpenGl_AspectText& theAspect,
- const Standard_Integer theHeight);
+ const Standard_Integer theHeight,
+ const unsigned int theResolution);
//! Find shared resource for specified font or initialize new one
Standard_EXPORT static Handle(OpenGl_Font) FindFont (const Handle(OpenGl_Context)& theCtx,
const OpenGl_AspectText& theAspect,
const Standard_Integer theHeight,
+ const unsigned int theResolution,
const TCollection_AsciiString theKey);
//! Compute text width
const NCollection_String& theText,
const OpenGl_AspectText& theTextAspect,
const OpenGl_TextParam& theParams,
+ const unsigned int theResolution,
Standard_ShortReal& theWidth,
Standard_ShortReal& theAscent,
Standard_ShortReal& theDescent);
//! Perform rendering
Standard_EXPORT void Render (const Handle(OpenGl_PrinterContext)& thePrintCtx,
const Handle(OpenGl_Context)& theCtx,
- const OpenGl_AspectText& theTextAspect) const;
+ const OpenGl_AspectText& theTextAspect,
+ const unsigned int theResolution = Graphic3d_RenderingParams::THE_DEFAULT_RESOLUTION) const;
protected:
const Handle(OpenGl_Context)& theCtx,
const OpenGl_AspectText& theTextAspect,
const TEL_COLOUR& theColorText,
- const TEL_COLOUR& theColorSubs) const;
+ const TEL_COLOUR& theColorSubs,
+ const unsigned int theResolution) const;
protected:
static const OpenGl_AspectLine myDefaultAspectLine;
static const OpenGl_AspectFace myDefaultAspectFace;
static const OpenGl_AspectMarker myDefaultAspectMarker;
- static const OpenGl_AspectText myDefaultAspectText;
static const OpenGl_TextParam myDefaultTextParam =
{
AspectFace_applied (NULL),
AspectMarker_set (&myDefaultAspectMarker),
AspectMarker_applied (NULL),
- AspectText_set (&myDefaultAspectText),
- AspectText_applied (NULL),
- TextParam_set (&myDefaultTextParam),
- TextParam_applied (NULL),
ViewMatrix_applied (&myDefaultMatrix),
StructureMatrix_applied (&myDefaultMatrix),
myCullingMode (TelCullUndefined),
AspectFace_applied = NULL;
AspectMarker_set = &myDefaultAspectMarker;
AspectMarker_applied = NULL;
- AspectText_set = &myDefaultAspectText;
- AspectText_applied = NULL;
- TextParam_set = &myDefaultTextParam;
- TextParam_applied = NULL;
PolygonOffset_applied = THE_DEFAULT_POFFSET;
myCullingMode = TelCullUndefined;
if (theWithApply)
{
AspectText_applied = AspectText_set;
- TextParam_applied = TextParam_set;
}
return AspectText_set;
Standard_EXPORT const OpenGl_AspectMarker* SetAspectMarker (const OpenGl_AspectMarker* theAspect);
Standard_EXPORT const OpenGl_AspectText* SetAspectText (const OpenGl_AspectText* theAspect);
- void SetTextParam (const OpenGl_TextParam* theParam) { TextParam_set = theParam; }
-
//// THESE METHODS ARE EXPORTED AS THEY PROVIDE STATE INFO TO USERDRAW
Standard_EXPORT const OpenGl_AspectLine* AspectLine (const Standard_Boolean theWithApply);
Standard_EXPORT const OpenGl_AspectFace* AspectFace (const Standard_Boolean theWithApply);
Standard_EXPORT const OpenGl_AspectMarker* AspectMarker (const Standard_Boolean theWithApply);
Standard_EXPORT const OpenGl_AspectText* AspectText (const Standard_Boolean theWithApply);
- inline const OpenGl_TextParam* AspectTextParams() const
- {
- return TextParam_applied;
- }
//! Clear the applied aspect state.
void ResetAppliedAspect();
const OpenGl_AspectMarker *AspectMarker_set, *AspectMarker_applied;
const OpenGl_AspectText *AspectText_set, *AspectText_applied;
- const OpenGl_TextParam *TextParam_set, *TextParam_applied;
-
const OpenGl_Matrix* ViewMatrix_applied;
const OpenGl_Matrix* StructureMatrix_applied;
return 1;
}
}
+ else if (aFlag == "-resolution")
+ {
+ if (++anArgIter >= theArgNb)
+ {
+ std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
+ return 1;
+ }
+
+ TCollection_AsciiString aResolution (theArgVec[anArgIter]);
+ if (aResolution.IsIntegerValue())
+ {
+ aView->ChangeRenderingParams().Resolution = static_cast<unsigned int> (Draw::Atoi (aResolution.ToCString()));
+ }
+ else
+ {
+ std::cout << "Error: wrong syntax at argument'" << anArg << "'.\n";
+ return 1;
+ }
+ }
else
{
std::cout << "Error: wrong syntax, unknown flag '" << anArg << "'\n";
"\n '-env on|off' Enables/disables environment map background"
"\n '-shadingModel model' Controls shading model from enumeration"
"\n color, flat, gouraud, phong"
+ "\n '-resolution value' Sets a new pixels density (PPI), defines scaling factor for parameters like text size"
"\n Unlike vcaps, these parameters dramatically change visual properties."
"\n Command is intended to control presentation quality depending on"
"\n hardware capabilities and performance.",
--- /dev/null
+puts "============"
+puts "OCC26298 make font resolution configurable"
+puts "============"
+puts ""
+pload VISUALIZATION
+
+vfont add [locate_data_file DejaVuSans.ttf] SansFont
+
+vclear
+vclose all
+
+vinit
+vtop
+
+vrenderparams -resolution 72
+
+vdrawtext t0 TopLeftText -pos -100 100 0 -font SansFont -color yellow -valign top -halign left
+vdrawtext t1 CenterText -pos 0 0 0 -font SansFont -color green -valign center -halign center
+vdrawtext t2 BottomRightText -pos 100 -100 0 -font SansFont -color red -valign bottom -halign right
+
+vfit
+
+vdump $imagedir/${casename}_1.png
+
+vrenderparams -resolution 96
+
+vdump $imagedir/${casename}_2.png
+
+vrenderparams -resolution 144
+
+vdump $imagedir/${casename}_3.png