diff --git a/samples/tcl/bottle.tcl b/samples/tcl/bottle.tcl index 724d330a66..8c8d7b0852 100755 --- a/samples/tcl/bottle.tcl +++ b/samples/tcl/bottle.tcl @@ -96,7 +96,7 @@ thrusections -N thread 1 0 tw1 tw2 puts "Putting together and writing \"Open CASCADE\"..." # define text -text2brep text2d OpenCASCADE Times-Roman 8 bold composite=0 +text2brep text2d OpenCASCADE -font Times-Roman -height 8 -aspect bold -composite off prism text text2d 0 0 2 trotate text 0 0 0 0 1 0 90 ttranslate text 24.75 -2 65 diff --git a/samples/tcl/cpu.tcl b/samples/tcl/cpu.tcl index 4cf4d2af90..3db0c24b87 100644 --- a/samples/tcl/cpu.tcl +++ b/samples/tcl/cpu.tcl @@ -77,10 +77,10 @@ set font "Arial Unicode MS" #text2brep title $text "Arial Unicode MS" 1.7 x=10 y=24 z=4.51 # alternative variant to work-around issue #25852 set text "i\u20dd\u20dd11\nINTEL\u20dd CORE\u2122 i7-4790\nSR1QF 3.60GHZ\nMALAY\nL411B540 \u20dd" -text2brep title0 $text $font 1.7 x=10 y=24 z=4.51 -text2brep title1 " M C" $font 0.77 x=10 y=24.2 z=4.51 -text2brep title2 "R" $font 0.77 x=15.3 y=21.9 z=4.51 -text2brep title3 "e4" $font 0.7 x=18.6 y=15.1 z=4.51 +text2brep title0 $text -font $font -height 1.7 -pos 10 24 4.51 -valign topfirstline +text2brep title1 " M C" -font $font -height 0.77 -pos 10 24.2 4.51 +text2brep title2 "R" -font $font -height 0.77 -pos 15.3 21.9 4.51 +text2brep title3 "e4" -font $font -height 0.7 -pos 18.6 15.1 4.51 compound title0 title1 title2 title3 title puts "Adding contact pads..." diff --git a/samples/tcl/pencil.tcl b/samples/tcl/pencil.tcl index c48eb285ca..e56969c197 100644 --- a/samples/tcl/pencil.tcl +++ b/samples/tcl/pencil.tcl @@ -27,7 +27,7 @@ bcommon body b e bcut body body c bcommon core cx e -text2brep text "CAD Assistant" Times 10 +text2brep text "CAD Assistant" -font Times -height 10 ttranslate text 10 -4 10 prism tr text 0 0 -1 bfuse body body tr diff --git a/samples/tcl/snowflake.tcl b/samples/tcl/snowflake.tcl index d31dc5a492..06da6b6d25 100644 --- a/samples/tcl/snowflake.tcl +++ b/samples/tcl/snowflake.tcl @@ -107,13 +107,13 @@ polyline t9 154 -80 0 154 -60 0 compound frame t1 t2 t3 t4 t5 t6 t7 t8 t9 lines # add text -text2brep sample "SAMPLE" Arial 10 x=90 y=-55 bolditalic -text2brep occ "Open CASCADE" Times 6 x=125 y=-95 -text2brep name "Snowflake" Courier 7 x=65 y=-75 italic -text2brep material "Ice" Courier 7 x=75 y=-95 italic -text2brep sheets "Sheets 1" Courier 3.5 x=145 y=-83 italic -text2brep scale "Scale\n\n1:100" Courier 3.5 x=157 y=-63 italic -text2brep mass "Mass\n\n1 mg" Courier 3.5 x=140 y=-63 italic +text2brep sample "SAMPLE" -font Arial -height 10 -pos 90 -55 0 -aspect bolditalic +text2brep occ "Open CASCADE" -font Times -height 6 -pos 125 -95 0 +text2brep name "Snowflake" -font Courier -height 7 -pos 65 -75 0 -aspect italic +text2brep material "Ice" -font Courier -height 7 -pos 75 -95 0 -aspect italic +text2brep sheets "Sheets 1" -font Courier -height 3.5 -pos 145 -83 0 -aspect italic +text2brep scale "Scale\n\n1:100" -font Courier -height 3.5 -pos 157 -63 0 -aspect italic -valign topfirstline +text2brep mass "Mass\n\n1 mg" -font Courier -height 3.5 -pos 140 -63 0 -aspect italic -valign topfirstline eval compound [explode sample w] sample eval compound [explode occ w] occ eval compound [explode name w] name diff --git a/src/AIS/AIS_Dimension.cxx b/src/AIS/AIS_Dimension.cxx index 034114a6e6..feca35f0a3 100755 --- a/src/AIS/AIS_Dimension.cxx +++ b/src/AIS/AIS_Dimension.cxx @@ -24,6 +24,7 @@ #include #include #include +#include #include #include #include @@ -422,7 +423,9 @@ void AIS_Dimension::DrawText (const Handle(Prs3d_Presentation)& thePresentation, // creating TopoDS_Shape for text Font_BRepFont aFont (aFontName, aFontAspect, aFontHeight); NCollection_Utf8String anUTFString = (Standard_Utf16Char* )theText.ToExtString(); - TopoDS_Shape aTextShape = aFont.RenderText (anUTFString); + + Font_BRepTextBuilder aBuilder; + TopoDS_Shape aTextShape = aBuilder.Perform (aFont, anUTFString); // compute text width with kerning Standard_Real aTextWidth = 0.0; diff --git a/src/Font/FILES b/src/Font/FILES index 10bee7ac04..b42bb13848 100644 --- a/src/Font/FILES +++ b/src/Font/FILES @@ -1,5 +1,7 @@ Font_BRepFont.cxx Font_BRepFont.hxx +Font_BRepTextBuilder.cxx +Font_BRepTextBuilder.hxx Font_FontAspect.hxx Font_FontMgr.cxx Font_FontMgr.hxx diff --git a/src/Font/Font_BRepFont.cxx b/src/Font/Font_BRepFont.cxx index e25f1d87bc..128d2b8f35 100755 --- a/src/Font/Font_BRepFont.cxx +++ b/src/Font/Font_BRepFont.cxx @@ -18,6 +18,7 @@ #include #include #include +#include #include #include #include @@ -463,57 +464,3 @@ Standard_Boolean Font_BRepFont::renderGlyph (const Standard_Utf32Char theChar, myCache.Bind (theChar, theShape); return !theShape.IsNull(); } - -// ======================================================================= -// function : RenderText -// purpose : -// ======================================================================= -TopoDS_Shape Font_BRepFont::RenderText (const NCollection_String& theString) -{ - if (theString.IsEmpty()) - { - return TopoDS_Shape(); - } - - gp_Trsf aTrsf; - gp_XYZ aPen; - Standard_Integer aLine = 0; - TopoDS_Shape aGlyphShape; - TopoDS_Compound aResult; - myBuilder.MakeCompound (aResult); - Standard_Mutex::Sentry aSentry (myMutex); - for (NCollection_Utf8Iter anIter = theString.Iterator(); *anIter != 0;) - { - const Standard_Utf32Char aCharCurr = *anIter; - const Standard_Utf32Char aCharNext = *++anIter; - if (aCharCurr == '\x0D' // CR (carriage return) - || aCharCurr == '\a' // BEL (alarm) - || aCharCurr == '\f' // FF (form feed) NP (new page) - || aCharCurr == '\b' // BS (backspace) - || aCharCurr == '\v') // VT (vertical tab) - { - continue; // skip unsupported carriage control codes - } - else if (aCharCurr == ' ' || aCharCurr == '\t') - { - aPen.SetX (aPen.X() + AdvanceX (aCharCurr, aCharNext)); - continue; - } - else if (aCharCurr == '\n') - { - ++aLine; - aPen.SetX (0.0); - aPen.SetY (-Standard_Real(aLine) * LineSpacing()); - continue; - } - - if (renderGlyph (aCharCurr, aGlyphShape)) - { - aTrsf.SetTranslation (gp_Vec (aPen)); - aGlyphShape.Move (aTrsf); - myBuilder.Add (aResult, aGlyphShape); - } - aPen.SetX (aPen.X() + AdvanceX (aCharCurr, aCharNext)); - } - return aResult; -} diff --git a/src/Font/Font_BRepFont.hxx b/src/Font/Font_BRepFont.hxx index 83afd067e2..28eac4ca5f 100755 --- a/src/Font/Font_BRepFont.hxx +++ b/src/Font/Font_BRepFont.hxx @@ -18,6 +18,7 @@ #include #include #include +#include #include #include #include @@ -95,27 +96,6 @@ public: //! Notice that altering this flag clears currently accumulated cache! Standard_EXPORT void SetCompositeCurveMode (const Standard_Boolean theToConcatenate); -public: - - //! Render text as BRep shape. - //! @param theString text in UTF-8 encoding - //! @return result shape within XOY plane and start position (0,0,0) on the baseline - Standard_EXPORT TopoDS_Shape RenderText (const NCollection_String& theString); - - //! Render text as BRep shape. - //! @param theString text in UTF-8 encoding - //! @param thePenLoc start position and orientation on the baseline - //! @return result shape with pen transformation applied as shape location - TopoDS_Shape RenderText (const NCollection_String& theString, - const gp_Ax3& thePenLoc) - { - TopoDS_Shape aResult = RenderText (theString); - gp_Trsf aTrsf; - aTrsf.SetTransformation (thePenLoc, gp_Ax3 (gp::XOY())); - aResult.Move (aTrsf); - return aResult; - } - public: //! @return vertical distance from the horizontal baseline to the highest character coordinate. @@ -172,6 +152,18 @@ public: return myScaleUnits * Standard_Real(Font_FTFont::AdvanceY (theUChar, theUCharNext)); } + //! Returns scaling factor for current font size. + Standard_Real Scale() const + { + return myScaleUnits; + } + + //! Returns mutex. + Standard_Mutex& Mutex() + { + return myMutex; + } + protected: //! Render single glyph as TopoDS_Shape. This method does not lock the mutex. @@ -205,7 +197,7 @@ protected: //! @name Protected fields Handle(Geom_Surface) mySurface; //!< surface to place glyphs on to Standard_Real myPrecision; //!< algorithm precision Standard_Real myScaleUnits; //!< scale font rendering units into model units - Standard_Boolean myIsCompositeCurve; //!< flag to merge C1 curves of each contour into single C0 curve, ON by default + Standard_Boolean myIsCompositeCurve; //!< flag to merge C1 curves of each contour into single C0 curve, OFF by default protected: //! @name Shared temporary variables for glyph construction diff --git a/src/Font/Font_BRepTextBuilder.cxx b/src/Font/Font_BRepTextBuilder.cxx new file mode 100644 index 0000000000..2304c19957 --- /dev/null +++ b/src/Font/Font_BRepTextBuilder.cxx @@ -0,0 +1,89 @@ +// Created on: 2015-08-10 +// Created by: Ilya SEVRIKOV +// Copyright (c) 2013-2014 OPEN CASCADE SAS +// +// This file is part of Open CASCADE Technology software library. +// +// This library is free software; you can redistribute it and/or modify it under +// the terms of the GNU Lesser General Public License version 2.1 as published +// by the Free Software Foundation, with special exception defined in the file +// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT +// distribution for complete text of the license and disclaimer of any warranty. +// +// Alternatively, this file may be used under the terms of Open CASCADE +// commercial license or contractual agreement. + +#include + +// ======================================================================= +// Function : Perfrom +// Purpose : +// ======================================================================= +TopoDS_Shape Font_BRepTextBuilder::Perform (Font_BRepFont& theFont, + const Font_TextFormatter& theFormatter, + const gp_Ax3& thePenLoc) +{ + gp_Trsf aTrsf; + gp_XYZ aPen; + TopoDS_Shape aGlyphShape; + TopoDS_Compound aResult; + Standard_Mutex::Sentry aSentry (theFont.Mutex()); + + myBuilder.MakeCompound (aResult); + + Standard_Integer aSymbolCounter = 0; + Standard_Real aScaleUnits = theFont.Scale(); + for (NCollection_Utf8Iter anIter = theFormatter.String().Iterator(); *anIter != 0; ++anIter) + { + const Standard_Utf32Char aCharCurr = *anIter; + if (aCharCurr == '\x0D' // CR (carriage return) + || aCharCurr == '\a' // BEL (alarm) + || aCharCurr == '\f' // FF (form feed) NP (new page) + || aCharCurr == '\b' // BS (backspace) + || aCharCurr == '\v' // VT (vertical tab) + || aCharCurr == ' ' + || aCharCurr == '\t' + || aCharCurr == '\n') + { + continue; // skip unsupported carriage control codes + } + + const NCollection_Vec2& aCorner = theFormatter.TopLeft (aSymbolCounter); + aPen.SetCoord (aCorner.x() * aScaleUnits, aCorner.y() * aScaleUnits, 0.0); + aGlyphShape = theFont.RenderGlyph (aCharCurr); + if (!aGlyphShape.IsNull()) + { + aTrsf.SetTranslation (gp_Vec (aPen)); + aGlyphShape.Move (aTrsf); + myBuilder.Add (aResult, aGlyphShape); + } + + ++aSymbolCounter; + } + + aTrsf.SetTransformation (thePenLoc, gp_Ax3 (gp::XOY())); + aResult.Move (aTrsf); + + return aResult; +} + +// ======================================================================= +// Function : Perform +// Purpose : +// ======================================================================= +TopoDS_Shape Font_BRepTextBuilder::Perform (Font_BRepFont& theFont, + const NCollection_String& theString, + const gp_Ax3& thePenLoc, + const Graphic3d_HorizontalTextAlignment theHAlign, + const Graphic3d_VerticalTextAlignment theVAlign) +{ + Font_TextFormatter aFormatter; + + aFormatter.Reset(); + aFormatter.SetupAlignment (theHAlign, theVAlign); + + aFormatter.Append (theString, *(reinterpret_cast (&theFont))); + aFormatter.Format(); + + return Perform (theFont, aFormatter, thePenLoc); +} diff --git a/src/Font/Font_BRepTextBuilder.hxx b/src/Font/Font_BRepTextBuilder.hxx new file mode 100644 index 0000000000..af03f79e3d --- /dev/null +++ b/src/Font/Font_BRepTextBuilder.hxx @@ -0,0 +1,51 @@ +// Created on: 2015-08-10 +// Created by: Ilya SEVRIKOV +// Copyright (c) 2013-2014 OPEN CASCADE SAS +// +// This file is part of Open CASCADE Technology software library. +// +// This library is free software; you can redistribute it and/or modify it under +// the terms of the GNU Lesser General Public License version 2.1 as published +// by the Free Software Foundation, with special exception defined in the file +// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT +// distribution for complete text of the license and disclaimer of any warranty. +// +// Alternatively, this file may be used under the terms of Open CASCADE +// commercial license or contractual agreement. + +#ifndef Font_BRepTextBuilder_Header +#define Font_BRepTextBuilder_Header + +#include +#include +#include + +//! Represents class for applying text formatting. +class Font_BRepTextBuilder +{ +public: + //! Render text as BRep shape. + //! @param theString text in UTF-8 encoding + //! @param thePenLoc start position and orientation on the baseline + //! @param theFormatter formatter which defines alignment for the text + //! @return result shape with pen transformation applied as shape location + Standard_EXPORT TopoDS_Shape Perform (Font_BRepFont& theFont, + const Font_TextFormatter& theFormatter, + const gp_Ax3& thePenLoc = gp_Ax3()); + //! Render text as BRep shape. + //! @param theString text in UTF-8 encoding + //! @param thePenLoc start position and orientation on the baseline + //! @param theHAlign horizontal alignment of the text + //! @param theVAlign vertical alignment of the text + //! @return result shape with pen transformation applied as shape location + Standard_EXPORT TopoDS_Shape Perform (Font_BRepFont& theFont, + const NCollection_String& theString, + const gp_Ax3& thePenLoc = gp_Ax3(), + const Graphic3d_HorizontalTextAlignment theHAlign = Graphic3d_HTA_LEFT, + const Graphic3d_VerticalTextAlignment theVAlign = Graphic3d_VTA_BOTTOM); + +protected: + BRep_Builder myBuilder; +}; + +#endif // Font_BRepTextBuilder_Header diff --git a/src/Font/Font_TextFormatter.cxx b/src/Font/Font_TextFormatter.cxx index a190f347da..6ed04745b1 100644 --- a/src/Font/Font_TextFormatter.cxx +++ b/src/Font/Font_TextFormatter.cxx @@ -298,11 +298,18 @@ void Font_TextFormatter::Format() if (myAlignY == Graphic3d_VTA_BOTTOM) { myBndTop = -myLineSpacing - myPenCurrLine; - moveY (myCorners, myBndTop, 0, myRectsNb - 1); } else if (myAlignY == Graphic3d_VTA_CENTER) { myBndTop = 0.5f * (myLineSpacing * Standard_ShortReal(myLinesNb)); + } + else if (myAlignY == Graphic3d_VTA_TOPFIRSTLINE) + { + myBndTop = myAscender; + } + + if (myAlignY != Graphic3d_VTA_TOP) + { moveY (myCorners, myBndTop, 0, myRectsNb - 1); } } diff --git a/src/Graphic3d/Graphic3d_VerticalTextAlignment.hxx b/src/Graphic3d/Graphic3d_VerticalTextAlignment.hxx index 71f4706e1b..df15c45597 100644 --- a/src/Graphic3d/Graphic3d_VerticalTextAlignment.hxx +++ b/src/Graphic3d/Graphic3d_VerticalTextAlignment.hxx @@ -21,9 +21,10 @@ //! relative to its anchor. enum Graphic3d_VerticalTextAlignment { -Graphic3d_VTA_BOTTOM, -Graphic3d_VTA_CENTER, -Graphic3d_VTA_TOP +Graphic3d_VTA_BOTTOM, //!< The anchor lies on the last line of the text. +Graphic3d_VTA_CENTER, //!< The anchor lies on the center of the text (not bounding box). +Graphic3d_VTA_TOP, //!< The anchor lies on the line preceding to the first line of the text. +Graphic3d_VTA_TOPFIRSTLINE //!< The anchor lies on the first line of the text. }; #endif // _Graphic3d_VerticalTextAlignment_HeaderFile diff --git a/src/ViewerTest/ViewerTest_ObjectCommands.cxx b/src/ViewerTest/ViewerTest_ObjectCommands.cxx index a0635ab42a..c04dff3fc6 100644 --- a/src/ViewerTest/ViewerTest_ObjectCommands.cxx +++ b/src/ViewerTest/ViewerTest_ObjectCommands.cxx @@ -23,6 +23,7 @@ #include #include +#include #include #include #include @@ -148,6 +149,8 @@ extern Standard_Boolean VDisplayAISObject (const TCollection_AsciiString& theNam Standard_Boolean theReplaceIfExists = Standard_True); extern int ViewerMainLoop(Standard_Integer argc, const char** argv); extern Handle(AIS_InteractiveContext)& TheAISContext(); +extern Standard_Boolean parseOnOff (Standard_CString theArg, + Standard_Boolean& theIsOn); //============================================================================== @@ -2544,6 +2547,10 @@ static int VDrawText (Draw_Interpretor& theDI, { aTextPrs->SetVJustification (Graphic3d_VTA_BOTTOM); } + else if (aType == "topfirstline") + { + aTextPrs->SetVJustification (Graphic3d_VTA_TOPFIRSTLINE); + } else { std::cout << "Error: wrong syntax at '" << aParam.ToCString() << "'.\n"; @@ -5265,69 +5272,210 @@ static TCollection_AsciiString fontStyleString (const Font_FontAspect theAspect) //function : TextToBrep //purpose : Tool for conversion text to occt-shapes //======================================================================= - static int TextToBRep (Draw_Interpretor& /*theDI*/, Standard_Integer theArgNb, const char** theArgVec) { // Check arguments - if (theArgNb < 5) + if (theArgNb < 3) { std::cerr << "Error: " << theArgVec[0] << " - invalid syntax\n"; return 1; } - Standard_Integer anArgIter = 1; - Standard_CString aResName = theArgVec[anArgIter++]; - Standard_CString aText = theArgVec[anArgIter++]; - Standard_CString aFontName = theArgVec[anArgIter++]; - const Standard_Real aSize = Atof (theArgVec[anArgIter++]); + Standard_Integer anArgIt = 1; + Standard_CString aName = theArgVec[anArgIt++]; + Standard_CString aText = theArgVec[anArgIt++]; - Font_BRepFont aFont; - Font_FontAspect aFontAspect = Font_FA_Regular; - Standard_Boolean isCompositeCurve = Standard_False; - gp_Ax3 aPenAx3 (gp::XOY()); - gp_Pnt aPenLoc; - while (anArgIter < theArgNb) + Font_BRepFont aFont; + TCollection_AsciiString aFontName ("Courier"); + Standard_Real aTextHeight = 16.0; + Font_FontAspect aFontAspect = Font_FA_Regular; + Standard_Boolean anIsCompositeCurve = Standard_False; + gp_Ax3 aPenAx3 (gp::XOY()); + gp_Dir aNormal (0.0, 0.0, 1.0); + gp_Dir aDirection (1.0, 0.0, 0.0); + gp_Pnt aPenLoc; + + Graphic3d_HorizontalTextAlignment aHJustification = Graphic3d_HTA_LEFT; + Graphic3d_VerticalTextAlignment aVJustification = Graphic3d_VTA_BOTTOM; + + for (; anArgIt < theArgNb; ++anArgIt) { - const TCollection_AsciiString anArg (theArgVec[anArgIter++]); - TCollection_AsciiString anArgCase (anArg); - anArgCase.LowerCase(); - if (anArgCase.Search ("x=") > -1) + TCollection_AsciiString aParam (theArgVec[anArgIt]); + aParam.LowerCase(); + + if (aParam == "-pos" + || aParam == "-position") { - aPenLoc.SetX (anArg.Token ("=", 2).RealValue()); + if (anArgIt + 3 >= theArgNb) + { + std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n"; + return 1; + } + + aPenLoc.SetX (Draw::Atof(theArgVec[++anArgIt])); + aPenLoc.SetY (Draw::Atof(theArgVec[++anArgIt])); + aPenLoc.SetZ (Draw::Atof(theArgVec[++anArgIt])); } - else if (anArgCase.Search ("y=") > -1) + else if (aParam == "-halign") { - aPenLoc.SetY (anArg.Token ("=", 2).RealValue()); + if (++anArgIt >= theArgNb) + { + std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n"; + return 1; + } + + TCollection_AsciiString aType (theArgVec[anArgIt]); + aType.LowerCase(); + if (aType == "left") + { + aHJustification = Graphic3d_HTA_LEFT; + } + else if (aType == "center") + { + aHJustification = Graphic3d_HTA_CENTER; + } + else if (aType == "right") + { + aHJustification = Graphic3d_HTA_RIGHT; + } + else + { + std::cout << "Error: wrong syntax at '" << aParam.ToCString() << "'.\n"; + return 1; + } } - else if (anArgCase.Search ("z=") > -1) + else if (aParam == "-valign") { - aPenLoc.SetZ (anArg.Token ("=", 2).RealValue()); + if (++anArgIt >= theArgNb) + { + std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n"; + return 1; + } + + TCollection_AsciiString aType (theArgVec[anArgIt]); + aType.LowerCase(); + if (aType == "top") + { + aVJustification = Graphic3d_VTA_TOP; + } + else if (aType == "center") + { + aVJustification = Graphic3d_VTA_CENTER; + } + else if (aType == "bottom") + { + aVJustification = Graphic3d_VTA_BOTTOM; + } + else if (aType == "topfirstline") + { + aVJustification = Graphic3d_VTA_TOPFIRSTLINE; + } + else + { + std::cout << "Error: wrong syntax at '" << aParam.ToCString() << "'.\n"; + return 1; + } } - else if (anArgCase.Search ("composite=") > -1) + else if (aParam == "-height") { - isCompositeCurve = (anArg.Token ("=", 2).IntegerValue() == 1); + if (++anArgIt >= theArgNb) + { + std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n"; + return 1; + } + + aTextHeight = Draw::Atof(theArgVec[anArgIt]); } - else if (parseFontStyle (anArgCase, aFontAspect)) + else if (aParam == "-aspect") { - // + if (++anArgIt >= theArgNb) + { + std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n"; + return 1; + } + + TCollection_AsciiString anOption (theArgVec[anArgIt]); + anOption.LowerCase(); + + if (anOption.IsEqual ("regular")) + { + aFontAspect = Font_FA_Regular; + } + else if (anOption.IsEqual ("bold")) + { + aFontAspect = Font_FA_Bold; + } + else if (anOption.IsEqual ("italic")) + { + aFontAspect = Font_FA_Italic; + } + else if (anOption.IsEqual ("bolditalic")) + { + aFontAspect = Font_FA_BoldItalic; + } + else + { + std::cout << "Error: wrong syntax at '" << aParam.ToCString() << "'.\n"; + return 1; + } + } + else if (aParam == "-font") + { + if (++anArgIt >= theArgNb) + { + std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n"; + return 1; + } + + aFontName = theArgVec[anArgIt]; + } + else if (aParam == "-composite") + { + if (++anArgIt >= theArgNb) + { + std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n"; + return 1; + } + + parseOnOff (theArgVec[anArgIt], anIsCompositeCurve); + } + else if (aParam == "-plane") + { + if (anArgIt + 6 >= theArgNb) + { + std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n"; + return 1; + } + + Standard_Real aX = Draw::Atof (theArgVec[++anArgIt]); + Standard_Real aY = Draw::Atof (theArgVec[++anArgIt]); + Standard_Real aZ = Draw::Atof (theArgVec[++anArgIt]); + aNormal.SetCoord (aX, aY, aZ); + + aX = Draw::Atof (theArgVec[++anArgIt]); + aY = Draw::Atof (theArgVec[++anArgIt]); + aZ = Draw::Atof (theArgVec[++anArgIt]); + aDirection.SetCoord (aX, aY, aZ); } else { - std::cerr << "Warning! Unknown argument '" << anArg.ToCString() << "'\n"; + std::cerr << "Warning! Unknown argument '" << aParam << "'\n"; } } - aFont.SetCompositeCurveMode (isCompositeCurve); - if (!aFont.Init (aFontName, aFontAspect, aSize)) + aFont.SetCompositeCurveMode (anIsCompositeCurve); + if (!aFont.Init (aFontName.ToCString(), aFontAspect, aTextHeight)) { std::cerr << "Font initialization error\n"; return 1; } - aPenAx3.SetLocation (aPenLoc); - DBRep::Set (aResName, aFont.RenderText (aText, aPenAx3)); + aPenAx3 = gp_Ax3 (aPenLoc, aNormal, aDirection); + + Font_BRepTextBuilder aBuilder; + DBRep::Set (aName, aBuilder.Perform (aFont, aText, aPenAx3, aHJustification, aVJustification)); return 0; } @@ -6118,7 +6266,7 @@ void ViewerTest::ObjectCommands(Draw_Interpretor& theCommands) "\n\t\t: [-pos X=0 Y=0 Z=0]" "\n\t\t: [-color {R G B|name}=yellow]" "\n\t\t: [-halign {left|center|right}=left]" - "\n\t\t: [-valign {top|center|bottom}=bottom}]" + "\n\t\t: [-valign {top|center|bottom|topfirstline}=bottom}]" "\n\t\t: [-angle angle=0]" "\n\t\t: [-zoom {0|1}=0]" "\n\t\t: [-height height=16]" @@ -6236,7 +6384,15 @@ void ViewerTest::ObjectCommands(Draw_Interpretor& theCommands) __FILE__, VMarkersTest, group); theCommands.Add ("text2brep", - "text2brep: res text fontName fontSize [x=0.0 y=0.0 z=0.0 composite=1 {regular,bold,italic,bolditalic=regular}]\n", + "text2brep: name text" + "\n\t\t: [-pos X=0 Y=0 Z=0]" + "\n\t\t: [-halign {left|center|right}=left]" + "\n\t\t: [-valign {top|center|bottom|topfirstline}=bottom}]" + "\n\t\t: [-height height=16]" + "\n\t\t: [-aspect {regular|bold|italic|bolditalic}=regular]" + "\n\t\t: [-font font=Courier]" + "\n\t\t: [-composite {on|off}=off]" + "\n\t\t: [-plane NormX NormY NormZ DirX DirY DirZ]", __FILE__, TextToBRep, group); theCommands.Add ("vfont", "vfont [add pathToFont [fontName] [regular,bold,italic,bolditalic=undefined]]" diff --git a/tests/3rdparty/fonts/B1 b/tests/3rdparty/fonts/B1 index 5fe3428139..c9981463f4 100644 --- a/tests/3rdparty/fonts/B1 +++ b/tests/3rdparty/fonts/B1 @@ -20,8 +20,7 @@ foreach aSize $THE_FONT_SIZES { vpoint aPnt_$aSize 0.0 $aLine 0.0 vdrawtext "Line_$aLineId" $aText -pos 0.0 $aLine 0.0 -color 0.0 1.0 1.0 -halign left -valign top -angle 000 -zoom 1 -height $aSize -aspect bolditalic -font $THE_FONT_NAME - text2brep aBText_$aSize $aText $THE_FONT_NAME $aSize bolditalic composite=0 - ttranslate aBText_$aSize 0.0 $aLine 0.0 + text2brep aBText_$aSize $aText -font $THE_FONT_NAME -height $aSize -aspect bolditalic -composite off -pos 0.0 $aLine 0.0 -valign topfirstline vdisplay aBText_$aSize set aLine [expr $aLine - 4.0 * $aSize] set aLineId [expr $aLineId + 1] diff --git a/tests/3rdparty/fonts/B2 b/tests/3rdparty/fonts/B2 index 7e2bb4ebc9..6119e6d3bb 100644 --- a/tests/3rdparty/fonts/B2 +++ b/tests/3rdparty/fonts/B2 @@ -20,8 +20,7 @@ foreach aSize $THE_FONT_SIZES { vpoint aPnt_$aSize 0.0 $aLine 0.0 vdrawtext "Line_$aLineId" $aText -pos 0.0 $aLine 0.0 -color 0.0 1.0 1.0 -halign left -valign top -angle 000 -zoom 1 -height $aSize -aspect bolditalic -font $THE_FONT_NAME - text2brep aBText_$aSize $aText $THE_FONT_NAME $aSize bolditalic composite=1 - ttranslate aBText_$aSize 0.0 $aLine 0.0 + text2brep aBText_$aSize $aText -font $THE_FONT_NAME -height $aSize -aspect bolditalic -composite on -pos 0.0 $aLine 0.0 -valign topfirstline vdisplay aBText_$aSize set aLine [expr $aLine - 4.0 * $aSize] set aLineId [expr $aLineId + 1] diff --git a/tests/3rdparty/fonts/B3 b/tests/3rdparty/fonts/B3 index a58c1ec53d..ab9fc61851 100644 --- a/tests/3rdparty/fonts/B3 +++ b/tests/3rdparty/fonts/B3 @@ -18,8 +18,8 @@ zxcvbnm,./ ZXCVBNM<>?§ } -text2brep aBTextN $THE_TEXT $THE_FONT_NAME $THE_FONT_SIZE regular composite=0 -text2brep aBTextC $THE_TEXT $THE_FONT_NAME $THE_FONT_SIZE regular composite=1 +text2brep aBTextN $THE_TEXT -font $THE_FONT_NAME -height $THE_FONT_SIZE -aspect regular -composite off +text2brep aBTextC $THE_TEXT -font $THE_FONT_NAME -height $THE_FONT_SIZE -aspect regular -composite on checkshape aBTextN checkshape aBTextC diff --git a/tests/3rdparty/fonts/B4 b/tests/3rdparty/fonts/B4 new file mode 100644 index 0000000000..9014f7577a --- /dev/null +++ b/tests/3rdparty/fonts/B4 @@ -0,0 +1,46 @@ +puts "============" +puts "OCC24272 Provide basic text formatting routines for Font_BRepFont" +puts "Test case prints 3D brep text with different text alignment styles" +puts "============" +puts "" + +vtrihedron trihedr +vright + +vsetdispmode 1 + +vpoint pTL -700 100 600 +text2brep Text0 "Top-Left\nFirst line\nLion The Second\n3rd" -pos -700 100 600 -halign left -valign top -height 50 -aspect regular -font Times-Roman -plane 0 -1 0 1 0 0 + +vpoint pTC 0 100 600 +text2brep Text1 "Top-Center\nFirst line\nLion The Second\n3rd" -pos 0 100 600 -halign center -valign top -height 50 -aspect regular -font Times-Roman -plane 0 -1 0 1 0 0 + +vpoint pTR 700 100 600 +text2brep Text2 "Top-Right\nFirst line\nLion The Second\n3rd" -pos 700 100 600 -halign right -valign top -height 50 -aspect regular -font Times-Roman -plane 0 -1 0 1 0 0 + +vpoint pCL -700 100 -100 +text2brep Text3 "Center-Left\nFirst line\nLion The Second\n3rd" -pos -700 100 -100 -halign left -valign center -height 50 -aspect regular -font Times-Roman -plane 0 -1 0 1 0 0 + +vpoint pCC 0 100 -100 +text2brep Text4 "Center-Center\nFirst line\nLion The Second\n3rd" -pos 0 100 -100 -halign center -valign center -height 50 -aspect regular -font Times-Roman -plane 0 -1 0 1 0 0 + +vpoint pCR 700 100 -100 +text2brep Text5 "Center-Right\nFirst line\nLion The Second\n3rd" -pos 700 100 -100 -halign right -valign center -height 50 -aspect regular -font Times-Roman -plane 0 -1 0 1 0 0 + +vpoint pBL -700 100 -700 +text2brep Text6 "Bottom-Left\nFirst line\nLion The Second\n3rd" -pos -700 100 -700 -halign left -valign bottom -height 50 -aspect regular -font Times-Roman -plane 0 -1 0 1 0 0 + +vpoint pBC 0 100 -700 +text2brep Text7 "Bottom-Center\nFirst line\nLion The Second\n3rd" -pos 0 100 -700 -halign center -valign bottom -height 50 -aspect regular -font Times-Roman -plane 0 -1 0 1 0 0 + +vpoint pBR 700 100 -700 +text2brep Text8 "Bottom-Right\nFirst line\nLion The Second\n3rd" -pos 700 100 -700 -halign right -valign bottom -height 50 -aspect regular -font Times-Roman -plane 0 -1 0 1 0 0 + +vdisplay Text0 Text1 Text2 Text3 Text4 Text5 Text6 Text7 Text8 -noupdate +vsetcolor Text0 Text1 Text2 0 1 1 +vsetcolor Text3 Text4 Text5 1 1 1 +vsetcolor Text6 Text7 Text8 1 1 0 + +vfit + +vfps diff --git a/tests/3rdparty/fonts/B5 b/tests/3rdparty/fonts/B5 new file mode 100644 index 0000000000..ed6882bffe --- /dev/null +++ b/tests/3rdparty/fonts/B5 @@ -0,0 +1,46 @@ +puts "============" +puts "OCC24272 Provide basic text formatting routines for Font_BRepFont" +puts "Test case prints 3D brep text with different text alignment styles" +puts "============" +puts "" + +vtrihedron trihedr +vright + +vsetdispmode 1 + +vpoint pTL -700 100 600 +text2brep Text0 " Top-Left\nFirst line \nLion The Second\n 3rd " -pos -700 100 600 -halign left -valign top -height 50 -aspect bold -font Arial -plane 0 -1 0 1 0 0 + +vpoint pTC 0 100 600 +text2brep Text1 " Top-Center\nFirst line \nLion The Second\n 3rd " -pos 0 100 600 -halign center -valign top -height 50 -aspect bold -font Arial -plane 0 -1 0 1 0 0 + +vpoint pTR 700 100 600 +text2brep Text2 " Top-Right\nFirst line \nLion The Second\n 3rd " -pos 700 100 600 -halign right -valign top -height 50 -aspect bold -font Arial -plane 0 -1 0 1 0 0 + +vpoint pCL -700 100 -100 +text2brep Text3 " Center-Left\nFirst line \nLion The Second\n 3rd " -pos -700 100 -100 -halign left -valign center -height 50 -aspect bold -font Arial -plane 0 -1 0 1 0 0 + +vpoint pCC 0 100 -100 +text2brep Text4 " Center-Center\nFirst line \nLion The Second\n 3rd " -pos 0 100 -100 -halign center -valign center -height 50 -aspect bold -font Arial -plane 0 -1 0 1 0 0 + +vpoint pCR 700 100 -100 +text2brep Text5 " Center-Right\nFirst line \nLion The Second\n 3rd " -pos 700 100 -100 -halign right -valign center -height 50 -aspect bold -font Arial -plane 0 -1 0 1 0 0 + +vpoint pBL -700 100 -700 +text2brep Text6 " Bottom-Left\nFirst line \nLion The Second\n 3rd " -pos -700 100 -700 -halign left -valign bottom -height 50 -aspect bold -font Arial -plane 0 -1 0 1 0 0 + +vpoint pBC 0 100 -700 +text2brep Text7 " Bottom-Center\nFirst line \nLion The Second\n 3rd " -pos 0 100 -700 -halign center -valign bottom -height 50 -aspect bold -font Arial -plane 0 -1 0 1 0 0 + +vpoint pBR 700 100 -700 +text2brep Text8 " Bottom-Right\nFirst line \nLion The Second\n 3rd " -pos 700 100 -700 -halign right -valign bottom -height 50 -aspect bold -font Arial -plane 0 -1 0 1 0 0 + +vdisplay Text0 Text1 Text2 Text3 Text4 Text5 Text6 Text7 Text8 -noupdate +vsetcolor Text0 Text1 Text2 0 1 1 +vsetcolor Text3 Text4 Text5 1 1 1 +vsetcolor Text6 Text7 Text8 1 1 0 + +vfit + +vfps diff --git a/tests/bugs/vis/bug25783_1 b/tests/bugs/vis/bug25783_1 index a1fbb03452..48bbb9cc03 100644 --- a/tests/bugs/vis/bug25783_1 +++ b/tests/bugs/vis/bug25783_1 @@ -9,31 +9,31 @@ vclear vaxo # display polyline in overlay -text2brep tcc "Center" Times-Roman 30 +text2brep tcc "Center" -font Times-Roman -height 30 vdisplay tcc -2d -osd polyline lcc -50 -50 0 -50 50 0 50 50 0 50 0 0 0 -50 0 -50 -50 0 vdisplay lcc -2d -overlay # display polyline in overlay in the bottom left corner of the view -text2brep tbl "Bottom-Left" Times-Roman 30 +text2brep tbl "Bottom-Left" -font Times-Roman -height 30 vdisplay tbl -2d -trsfPersPos -1 -1 5 -osd polyline lbl 0 0 0 0 100 0 100 100 0 100 50 0 50 0 0 0 0 0 vdisplay lbl -2d -trsfPersPos -1 -1 3 -overlay # display polyline in overlay in the top left corner of the view -text2brep ttl "Top-Left" Times-Roman 30 x=-27 y=0 +text2brep ttl "Top-Left" -font Times-Roman -height 30 -pos -27 0 0 vdisplay ttl -2d -trsfPersPos -1 1 30 -osd polyline ltl 0 -100 0 0 0 0 100 0 0 100 -50 0 50 -100 0 0 -100 0 vdisplay ltl -2d -trsfPersPos -1 1 3 -overlay # display polyline in overlay in the top right corner of the view -text2brep ttr "Top-Right" Times-Roman 30 x=-100 y=0 +text2brep ttr "Top-Right" -font Times-Roman -height 30 -pos -100 0 0 vdisplay ttr -2d -trsfPersPos 1 1 30 -osd polyline ltr -100 -100 0 -100 0 0 0 0 0 0 -50 0 -50 -100 0 -100 -100 0 vdisplay ltr -2d -trsfPersPos 1 1 3 -overlay # display polyline in overlay in the bottom right corner of the view -text2brep tbr "Bottom-Right" Times-Roman 30 x=-165 y=0 +text2brep tbr "Bottom-Right" -font Times-Roman -height 30 -pos -165 0 0 vdisplay tbr -2d -trsfPersPos 1 -1 5 -osd polyline lbr -100 0 0 -100 100 0 0 100 0 0 50 0 -50 0 0 -100 0 0 vdisplay lbr -2d -trsfPersPos 1 -1 3 -overlay diff --git a/tests/bugs/vis/bug25783_2 b/tests/bugs/vis/bug25783_2 index 25b62a1531..fd8b27cbe0 100644 --- a/tests/bugs/vis/bug25783_2 +++ b/tests/bugs/vis/bug25783_2 @@ -9,31 +9,31 @@ vclear vaxo # display polyline in overlay -text2brep tcc "Center" Times-Roman 30 +text2brep tcc "Center" -font Times-Roman -height 30 vdisplay tcc -2dTopDown -osd polyline lcc -50 -50 0 -50 50 0 50 50 0 50 0 0 0 -50 0 -50 -50 0 vdisplay lcc -2dTopDown -overlay # display polyline in overlay in the top left corner of the view -text2brep ttl "Top-Left" Times-Roman 30 +text2brep ttl "Top-Left" -font Times-Roman -height 30 vdisplay ttl -2dTopDown -trsfPersPos -1 -1 5 -osd polyline ltl 0 0 0 0 100 0 100 100 0 100 50 0 50 0 0 0 0 0 vdisplay ltl -2dTopDown -trsfPersPos -1 -1 3 -overlay # display polyline in overlay in the bottom left corner of the view -text2brep tbl "Bottom-Left" Times-Roman 30 x=-27 y=0 +text2brep tbl "Bottom-Left" -font Times-Roman -height 30 -pos -27 0 0 vdisplay tbl -2dTopDown -trsfPersPos -1 1 30 -osd polyline lbl 0 -100 0 0 0 0 100 0 0 100 -50 0 50 -100 0 0 -100 0 vdisplay lbl -2dTopDown -trsfPersPos -1 1 3 -overlay # display polyline in overlay in the bottom right corner of the view -text2brep tbr Bottom-Right Times-Roman 30 x=-145 y=0 +text2brep tbr Bottom-Right -font Times-Roman -height 30 -pos -145 0 0 vdisplay tbr -2dTopDown -trsfPersPos 1 1 30 -osd polyline lbr -100 -100 0 -100 0 0 0 0 0 0 -50 0 -50 -100 0 -100 -100 0 vdisplay lbr -2dTopDown -trsfPersPos 1 1 3 -overlay # display polyline in overlay in the top right corner of the view -text2brep ttr "Top-Right" Times-Roman 30 x=-130 y=0 +text2brep ttr "Top-Right" -font Times-Roman -height 30 -pos -130 0 0 vdisplay ttr -2dTopDown -trsfPersPos 1 -1 5 -osd polyline ltr -100 0 0 -100 100 0 0 100 0 0 50 0 -50 0 0 -100 0 0 vdisplay ltr -2dTopDown -trsfPersPos 1 -1 3 -overlay diff --git a/tests/bugs/vis/bug26149 b/tests/bugs/vis/bug26149 index 55c8381408..48be5ee792 100644 --- a/tests/bugs/vis/bug26149 +++ b/tests/bugs/vis/bug26149 @@ -8,27 +8,27 @@ vinit View1 vclear vaxo -text2brep tcc "Center" Times-Roman 30 +text2brep tcc "Center" -font Times-Roman -height 30 vdisplay tcc -2d -underlay polyline lcc -50 -50 0 -50 50 0 50 50 0 50 0 0 0 -50 0 -50 -50 0 vdisplay lcc -2d -underlay -text2brep tbl "Bottom-Left" Times-Roman 30 +text2brep tbl "Bottom-Left" -font Times-Roman -height 30 vdisplay tbl -2d -trsfPersPos -1 -1 5 -underlay polyline lbl 0 0 0 0 100 0 100 100 0 100 50 0 50 0 0 0 0 0 vdisplay lbl -2d -trsfPersPos -1 -1 3 -underlay -text2brep ttl "Top-Left" Times-Roman 30 x=-27 y=0 +text2brep ttl "Top-Left" -font Times-Roman -height 30 -pos -27 0 0 vdisplay ttl -2d -trsfPersPos -1 1 30 -underlay polyline ltl 0 -100 0 0 0 0 100 0 0 100 -50 0 50 -100 0 0 -100 0 vdisplay ltl -2d -trsfPersPos -1 1 3 -underlay -text2brep ttr "Top-Right" Times-Roman 30 x=-100 y=0 +text2brep ttr "Top-Right" -font Times-Roman -height 30 -pos -100 0 0 vdisplay ttr -2d -trsfPersPos 1 1 30 -underlay polyline ltr -100 -100 0 -100 0 0 0 0 0 0 -50 0 -50 -100 0 -100 -100 0 vdisplay ltr -2d -trsfPersPos 1 1 3 -underlay -text2brep tbr "Bottom-Right" Times-Roman 30 x=-165 y=0 +text2brep tbr "Bottom-Right" -font Times-Roman -height 30 -pos -165 0 0 vdisplay tbr -2d -trsfPersPos 1 -1 5 -underlay polyline lbr -100 0 0 -100 100 0 0 100 0 0 50 0 -50 0 0 -100 0 0 vdisplay lbr -2d -trsfPersPos 1 -1 3 -underlay diff --git a/tests/v3d/raytrace/bug24819 b/tests/v3d/raytrace/bug24819 index 3d78a6b377..8be8c3e84f 100644 --- a/tests/v3d/raytrace/bug24819 +++ b/tests/v3d/raytrace/bug24819 @@ -21,7 +21,7 @@ vsetmaterial b2 Pewter vsettransparency b2 0.8 # brep text -text2brep t "text" "Arial" 8 +text2brep t "text" -font "Arial" -height 8 vdisplay t # overlay objects