This example demonstrates working with the text style record object for displaying and modifying its properties. This example uses a console menu that represents the following operations: getting and setting the shape status [T], text direction typeface [D], letter side typeface [S], text orientation typeface [O], uni-font filename [U], big-font filename [B], width scale factor [W], height scale factor [H], last height [L], and oblique angle [A].
The PrintTextStyleProperties() function requires a pointer to an existing text style record object and prints the listed properties of the passed text style. This function uses the fileName() method for displaying a uni-font filename, bigFontFileName() method for displaying a big-font filename, xScale() method for displaying the width scale factor, textSize() method for displaying the height scale factor, priorSize() method for displaying the last height, obliquingAngle() method for displaying the oblique angle, and the isBackwards(), isUpsideDown(), isVertical() methods for displaying the typeface.
The PrintTextStyleProperties() function has the following implementation:
void PrintTextStyleProperties(OdDbTextStyleTableRecord* pTextStyle)
{
wcout << L"\nH=" << pTextStyle->handle().ascii()
<< L"\n Name = \"" << pTextStyle->getName() << L"\""
<< L"\n Status: " << ((pTextStyle->isErased()) ? L"erased" : L"unerased")
<< ((pTextStyle->isDBRO()) ? L",resident" : L"")
<< ((pTextStyle->isModified()) ? L",modified" : L"")
<< ((pTextStyle->isShapeFile()) ? L",shape" : L",text")
<< ((pTextStyle->isDependent()) ? L",XRef-dependent" : L"")
<< L"\n Uni-font: \"" << pTextStyle->fileName() << L"\""
<< L"\n Big-font: \"" << pTextStyle->bigFontFileName() << L"\""
<< L"\n TypeFace: " << ((pTextStyle->isBackwards()) ? L"backward" : L"forward")
<< ((pTextStyle->isUpsideDown()) ? L",downside" : L",upside")
<< ((pTextStyle->isVertical()) ? L",vertical" : L",horizontal")
<< L"\n Width Scale Factor = " << pTextStyle->xScale()
<< L"\n Height Scale Factor = " << pTextStyle->textSize()
<< L"\n Last Height = " << pTextStyle->priorSize()
<< L"\n Oblique Angle = " << pTextStyle->obliquingAngle() << L" radians";
}
The ModifyTextStyleProperties() function requires a pointer to an existing text style record object and implements the console menu for the listed operations. The function creates a loop that inquires about the operation code and uses the switch statement to select whether the case must be performed. The function uses the PrintTextStyleProperties() function for displaying specific properties and the EntryFileName() function for entering the filename for the uni-font or big-font. The EntryFileName() function requires parameters for checking the filename as arguments and returns the filename entered by the user as an OdString value, or an empty string if the user cancels entry. The ModifyUCSProperties() function processes user actions in the loop until the user selects the [Q] operation.
When the user selects [P], the function displays the specific properties of the specified text style record object using the PrintTextStyleProperties() function.
When the user selects [T], the function inquires the new shape status and prompts for the letter S-shape or T-text. The function calls the setIsShapeFile() method and passes to it a True value if the user enters 'S' (shape status) or a False value if the user enters 'T' (text status). After setting, the function checks and displays the current shape status using the isShapeFile() method.
When the user selects [D], the function inquires about the new text direction typeface and prompts for the letter B-backward or F-forward. The function calls the setIsBackwards() method and passes to it a True value if the user enters 'B' (backward text) or a False value if the user enters 'F' (forward text). After setting, the function checks and displays the current text direction typeface using the isBackwards() method.
When the user selects [S], the function inquires about the new letter side typeface and prompts for the letter D-downside or U-upside. The function calls the setIsUpsideDown() method and passes to it a True value if the user enters 'D' (downside letters) or a False value if the user enters 'U' (upside letters). After setting, the function checks and displays the current letter side typeface using the isUpsideDown() method.
When the user selects [O], the function inquires about the new text orientation typeface and prompts for the letter V-vertical or H-horizontal. The function calls the setIsVertical() method and passes to it a True value if the user enters 'V' (vertical text) or a False value if the user enters 'H' (horizontal text). After setting, the function checks and displays the current text orientation typeface using the isVertical() method.
When the user selects [U] or [B], the function inquires about the name of the .shx font file using the EntryFileName() function. The EntryFileName() function gets the kDontCheck value as the first argument because the font file is placed in the directory specified by a system variable and a True value as a second argument because the property requires only the filename without a path. The EntryFileName() function checks whether the entered name does not contain a path, device letter, or inadmissible letters, and returns the name entered by the user or an empty string if the user cancels entry or if the name is incorrect. If the entered name is correct, the ModifyTextStyleProperties() function calls the setFileName() method to set the uni-font or the setBigFontFileName() method to set the big-font for the text style. If the entered name is incorrect, the function breaks to the console menu. The function gets and displays the current uni-font filename using the fileName() method and the current big-font filename using the bigFontFileName() method.
When the user selects [W], the function displays the current width scale factor using the xScale() method and inquires about a new width scale factor as a positive non-zero double value. If the entered value is incorrect or is negative, the function displays an error message and breaks to the console menu. If the entered value is correct, the function calls the setXScale() method and passes to it the entered value to set the new width scale factor for the text style.
When the user selects [H], the function displays the current height scale factor using the textSize() method and inquires about a new height scale factor as a positive double value. If the entered value is incorrect or is negative, the function displays an error message and breaks to the console menu. If the entered value is correct, the function calls the setTextSize() method and passes to it the entered value to set the new height scale factor for the text style.
When the user selects [L], the function displays the current last height using the priorSize() method and inquires about a new height as a positive double value. If the entered value is incorrect or is negative, the function displays an error message and breaks to the console menu. If the entered value is correct, the function calls the setPriorSize() method and passes to it the entered value to set the last height for the text style.
When the user selects [A], the function displays the current oblique angle using the obliquingAngle() method and inquires about a new angle as a double value in the range –85 to +85 degrees. If the entered value is incorrect, the function displays an error message and breaks to the console menu. If the entered value is correct, the function calls the setObliquingAngle() method and passes to it the entered value to set the oblique angle for the text style.
When the user selects [Q], the function ends the loop and returns in the calling function.
The ModifyTextStyleProperties() function has the following implementation:
#include "..\Common\DemoMain.h"
#include "DbTextStyleTable.h"
#include "DbTextStyleTableRecord.h"
#include <iostream>
using namespace std;
void ModifyTextStyleProperties(OdDbTextStyleTableRecord* pTextStyle)
{
wchar_t ch = L'\0';
double value;
OdString fontname;
wcout << L"\nStart modifying of the text style properties";
do {
switch(ch)
{
case L'P': // Print specific properties
case L'p':
PrintTextStyleProperties(pTextStyle);
wcout << L"\n";
break;
case L'T': // Set the Text|Shape status
case L't':
wcout << "\nEntry the text style status [S-shape|T-text]:>";
wcin >> ch;
if(ch == L'S' || ch == L's') pTextStyle->setIsShapeFile(true);
else if(ch == L'T' || ch == L't') pTextStyle->setIsShapeFile(false);
wcout << L"Status is set to: " << ((pTextStyle->isShapeFile()) ? L"Shape" : L"Text") << L"\n";
break;
case L'D': // Set the Direction typeface
case L'd':
wcout << "\nEntry the Direction typeface [B-backward|F-forward]:>";
wcin >> ch;
if(ch == L'B' || ch == L'b') pTextStyle->setIsBackwards(true);
else if(ch == L'F' || ch == L'f') pTextStyle->setIsBackwards(false);
wcout << L"Typeface is set to: " << ((pTextStyle->isBackwards()) ? L"Backward" : L"Forward") << L"\n";
break;
case L'S': // Set the Letter Side typeface
case L's':
wcout << "\nEntry the Letter Side typeface [D-downside|U-upside]:>";
wcin >> ch;
if(ch == L'D' || ch == L'd') pTextStyle->setIsUpsideDown(true);
else if(ch == L'U' || ch == L'u') pTextStyle->setIsUpsideDown(false);
wcout << L"Typeface is set to: " << ((pTextStyle->isUpsideDown()) ? L"Downside" : L"Upside") << L"\n";
break;
case L'O': // Set the Orientation typeface
case L'o':
wcout << "\nEntry the Orientation typeface [V-vertical|H-horizontal]:>";
wcin >> ch;
if(ch == L'V' || ch == L'v') pTextStyle->setIsVertical(true);
else if(ch == L'H' || ch == L'h') pTextStyle->setIsVertical(false);
wcout << L"Typeface is set to: " << ((pTextStyle->isVertical()) ? L"Vertical" : L"Horizontal") << L"\n";
break;
case L'U': // Set the Uni-Font filename
case L'u':
wcout << L"\nUni-font filename: \"" << pTextStyle->fileName() << L"\""
<< L"\nEntry a shx-file name:>";
if((fontname = EntryFileName(kDontCheck, true)).isEmpty()) break;
pTextStyle->setFileName(fontname);
wcout << L"Uni-font is set to: \"" << pTextStyle->fileName() << L"\"\n";
break;
case L'B': // Big-Font filename
case L'b':
wcout << L"\nBig-font filename: \"" << pTextStyle->bigFontFileName() << L"\""
<< L"\nEntry a shx-file name:>";
if((fontname = EntryFileName(kDontCheck, true)).isEmpty()) break;
pTextStyle->setBigFontFileName(fontname);
wcout << L"Big-font is set to: \"" << pTextStyle->bigFontFileName() << L"\"\n";
break;
case L'W': // Set the Width Scale Factor
case L'w':
wcout << L"\nCurrent width scale factor = " << pTextStyle->xScale()
<< L"\nEntry a new factor [f > 0]:>";
wcin >> value;
if(!wcin.fail() && wcin.peek() == 10)
{
if(value > 0.0001)
{
pTextStyle->setXScale(value);
wcout << L"Width Scale Factor is set to: " << pTextStyle->xScale() << L"\n";
}
else wcout << L"Error: Width Factor must be a positive non-zero double value\n";
}
else { wcin.clear(); wcin.sync(); wcout << L"Error: Invalid entered value\n"; }
break;
case L'H': // Set the Height Scale Factor
case L'h':
wcout << L"\nCurrent height scale factor = " << pTextStyle->textSize()
<< L"\nEntry a new factor (text size) [f >= 0]:>";
wcin >> value;
if(!wcin.fail() && wcin.peek() == 10)
{
if(value >= 0)
{
pTextStyle->setTextSize(value);
wcout << L"Height Scale Factor is set to: " << pTextStyle->textSize() << L"\n";
}
else wcout << L"Error: Height Factor must be a positive double value\n";
}
else { wcin.clear(); wcin.sync(); wcout << L"Error: Invalid entered value\n"; }
break;
case L'L': // Set the Last Height
case L'l':
wcout << L"\nCurrent last height = " << pTextStyle->priorSize() << L" units"
<< L"\nEntry a new height [H > 0]:>";
wcin >> value;
if(!wcin.fail() && wcin.peek() == 10)
{
if(value > 0.0001)
{
pTextStyle->setPriorSize(value);
wcout << L"Last Height is set to: " << pTextStyle->priorSize() << L"\n";
}
else wcout << L"Error: Height must be a positive non-zero double value\n";
}
else { wcin.clear(); wcin.sync(); wcout << L"Error: Invalid entered value\n"; }
break;
case L'A': // Set the Oblique Angle
case L'a':
wcout << L"\nCurrent oblique angle = " << pTextStyle->obliquingAngle() << L" radians"
<< L"\nEntry a new angle [-1.48...+1.48]:>";
wcin >> value;
if(!wcin.fail() && wcin.peek() == 10)
{
if(value >= -1.48352986 && value <= +1.48352986)
{
pTextStyle->setObliquingAngle(value);
wcout << L"Oblique Angle is set to: " << pTextStyle->obliquingAngle() << L" radians\n";
}
else wcout << L"Error: Absolute angle value must be less than 1.48352986 radians\n";
}
else { wcin.clear(); wcin.sync(); wcout << L"Error: Invalid entered value\n"; }
break;
case L'\0': // Skip an action
break;
default:
wcout << L"Incorrect operation\n";
}
wcout << L"\nSelected text style: \"" << pTextStyle->getName() << L"\"";
wcout << L"\nP. Print the specific properties";
wcout << L"\nT. Set the Text|Shape status";
wcout << L"\nD. Set the Direction typeface";
wcout << L"\nS. Set the Letter Side typeface";
wcout << L"\nO. Set the Orientation typeface";
wcout << L"\nU. Set the Uni-Font filename";
wcout << L"\nB. Set the Big-Font filename";
wcout << L"\nW. Set the Width Scale Factor";
wcout << L"\nH. Set the Height Scale Factor";
wcout << L"\nL. Set the Last Height";
wcout << L"\nA. Set the Oblique Angle";
wcout << L"\nQ. Quit";
wcout << L"\nSelect operation:>";
wcin >> ch;
}
while(ch != L'Q' && ch != L'q');
wcout << L"Stop modifying of the text style properties\n";
}
Testing gives the following results:
Start modifying of the text style properties
Selected text style: "Style_A"
P. Print the specific properties
T. Set the Text|Shape status
D. Set the Direction typeface
S. Set the Letter Side typeface
O. Set the Orientation typeface
U. Set the Uni-Font filename
B. Set the Big-Font filename
W. Set the Width Scale Factor
H. Set the Height Scale Factor
L. Set the Last Height
A. Set the Oblique Angle
Q. Quit
Select operation:>
When the operation is P-"Print the specific properties":
H=40
Name = "Style_A"
Status: unerased,resident,text
Uni-font: ""
Big-font: ""
TypeFace: forward,upside,horizontal
Width Scale Factor = 1
Height Scale Factor = 0.2
Last Height = 0.2
Oblique Angle = 0 radians
When the operation is T-"Set the Text|Shape status":
Entry the text style status [S-shape|T-text]:>T
Status is set to: Text
When the operation is D-"Set the Direction typeface":
Entry the Direction typeface [B-backward|F-forward]:>B
Typeface is set to: Backward
When the operation is S-"Set the Letter Side typeface":
Entry the Letter Side typeface [D-downside|U-upside]:>D
Typeface is set to: Downside
When the operation is O-"Set the Orientation typeface":
Entry the Orientation typeface [V-vertical|H-horizontal]:>V
Typeface is set to: Vertical
When the operation is U-"Set the Uni-Font filename":
Uni-font filename: ""
Entry a shx-file name:>complex.shx
Uni-font is set to: "complex.shx"
When the operation is B-"Set the Big-Font filename":
H=3FBig-font filename: ""
Entry a shx-file name:>bigfont.shx
Big-font is set to: "bigfont.shx"
When the operation is W-"Set the Width Scale Factor":
Current width scale factor = 1
Entry a new factor [f > 0]:>1.5
Width Scale Factor is set to: 1.5
When the operation is W-"Set the Width Scale Factor" and a value is incorrect:
Current width scale factor = 1.5
Entry a new factor [f > 0]:>-1
Error: Width Factor must be a positive non-zero double value
When the operation is H-"Set the Height Scale Factor":
Current height scale factor = 0.2
Entry a new factor (text size) [f >= 0]:>0.8
Height Scale Factor is set to: 0.8
When the operation is H-"Set the Height Scale Factor" and a value is incorrect:
Current height scale factor = 0.8
Entry a new factor (text size) [f >= 0]:>-1.5
Error: Height Factor must be a positive double value
When the operation is L-"Set the Last Height":
Current last height = 0.2 units
Entry a new height [H > 0]:>2.5
Last Height is set to: 2.5
When the operation is L-"Set the Last Height" and a value is incorrect:
Current last height = 2.5 units
Entry a new height [H > 0]:>-0.5
Error: Height must be a positive non-zero double value
When the operation is A-"Set the Oblique Angle" and a value is negative:
Current oblique angle = 0 radians
Entry a new angle [-1.48...+1.48]:>-0.854
Oblique Angle is set to: 5.42919 radians
When the operation is A-"Set the Oblique Angle" and a value is positive:
Current oblique angle = 5.42919 radians
Entry a new angle [-1.48...+1.48]:>1.14
Oblique Angle is set to: 1.14 radians
When the operation is A-"Set the Oblique Angle" and a value is incorrect:
Current oblique angle = 1.14 radians
Entry a new angle [-1.48...+1.48]:>2.5
Error: Absolute angle value must be less than 1.48352986 radians
After entry, the operation P-"Print the specific properties" displays:
H=40
Name = "Style_A"
Status: unerased,resident,modified,text
Uni-font: "complex.shx"
Big-font: "bigfont.shx"
TypeFace: backward,downside,vertical
Width Scale Factor = 1.5
Height Scale Factor = 0.8
Last Height = 2.5
Oblique Angle = 1.14 radians
Use the Q-"Quit" operation to exit:
Stop modifying of the text style properties
Copyright © 2002 – 2022. Open Design Alliance. All rights reserved.
|