This example demonstrates displaying and modifying the vertical and horizontal text alignment mode.
The AboutTextVerticalMode() function requires a value of the OdDb::TextVertMode enumerator and returns a string containing a comment about the passed vertical text alignment mode as an OdString value. The AboutTextHorizontalMode() function requires a value of the OdDb::TextHorzMode enumerator and returns a string containing a comment about the passed horizontal text alignment mode as an OdString value. Both functions declare a variable of the OdString type and use the format() method to convert the mode number. Then these functions check the passed mode using the switch statement to select the comment which must be attached to the resulting string.
The AboutTextVerticalMode() function has the following implementation:
OdString AboutTextVerticalMode(OdDb::TextVertMode mode)
{
OdString sAbout;
sAbout.format(L"[%d-", mode);
switch(mode)
{
case OdDb::kTextTop: sAbout += L"Top"; break;
case OdDb::kTextBase: sAbout += L"Base"; break;
case OdDb::kTextBottom: sAbout += L"Bottom"; break;
case OdDb::kTextVertMid: sAbout += L"Middle"; break;
default: sAbout += L"?";
}
return (sAbout += L"]");
}
The AboutTextHorizontalMode() function has the following implementation:
OdString AboutTextHorizontalMode(OdDb::TextHorzMode mode)
{
OdString sAbout;
sAbout.format(L"[%d-", mode);
switch(mode)
{
case OdDb::kTextFit: sAbout += L"Fit"; break;
case OdDb::kTextMid: sAbout += L"Middle"; break;
case OdDb::kTextLeft: sAbout += L"Left"; break;
case OdDb::kTextRight: sAbout += L"Right"; break;
case OdDb::kTextAlign: sAbout += L"Align"; break;
case OdDb::kTextCenter: sAbout += L"Center"; break;
default: sAbout += L"?";
}
return (sAbout += L"]");
}
The EntryTextVerticalMode() function requires a reference to a variable of a 16-bit Integer type in which the selected vertical text alignment mode must be saved as an argument and returns True if the user selects the mode, or False if the user cancels entry.
The EntryTextHorizontalMode() function requires a reference to a variable of a 16-bit Integer type in which the selected vertical text alignment mode must be saved as an argument and returns True if the user selects the mode, or False if the user cancels the entry.
Both functions organize a loop that displays the list of modes for vertical alignment or horizontal alignment, and then, requests the mode number as an Integer value. The vertical mode can take the following values: 0-base, 1-bottom, 2-middle, 3-top. The horizontal mode can take the following values: 0-left, 1-center, 2-right, 3-align, 4-middle, 5-fit. After entry, these functions check whether the value is in the corresponding range [0 to 3] or [0 to 5]. If the entry is incorrect or out of the range, these functions display an error message and repeat the loop. If the entry is correct, these functions return True as a result value and the selected mode number through its own argument in the calling function. If a user selects [4] or [6], these functions cancel the entry and return False as a result value.
The EntryTextVerticalMode() function has the following implementation:
bool EntryTextVerticalMode(OdInt16& refMode)
{
OdInt16 mode;
do {
wcout << L"\n0. Text Base"
<< L"\n1. Text Bottom"
<< L"\n2. Text Middle"
<< L"\n3. Text Top"
<< L"\n4. Quit"
<< L"\nEntry the vertical mode:>";
wcin >> mode;
if(!wcin.fail() && wcin.peek() == 10)
if(mode >= 0 && mode <= 3)
{
refMode = mode;
return true;
}
else if(mode == 4) return false;
else wcout << L"Error: Undefined vertical mode\n";
else { wcin.clear(); wcout << L"Error: Invalid entered value\n"; wcin.sync(); }
}
while(1);
}
The EntryTextHorizontalMode() function has the following implementation:
bool EntryTextHorizontalMode(OdInt16& refMode)
{
OdInt16 mode;
do {
wcout << L"\n0. Text Left"
<< L"\n1. Text Center"
<< L"\n2. Text Right"
<< L"\n3. Text Align"
<< L"\n4. Text Middle"
<< L"\n5. Text Fit"
<< L"\n6. Quit"
<< L"\nEntry the horizontal mode:>";
wcin >> mode;
if(!wcin.fail() && wcin.peek() == 10)
if(mode >= 0 && mode <= 5)
{
refMode = mode;
return true;
}
else if(mode == 6) return false;
else wcout << L"Error: Undefined horizontal mode\n";
else { wcin.clear(); wcout << L"Error: Invalid entered value\n"; wcin.sync(); }
}
while(1);
}
The testing function has the following implementation:
void DemoBase(OdDbDatabase* pDb)
{
OdInt16 mode;
EntryTextVerticalMode(mode);
wcout << L"Vertical mode = " << AboutTextVerticalMode((OdDb::TextVertMode) mode);
EntryTextHorizontalMode(mode);
wcout << L"Horizontal mode = " << AboutTextHorizontalMode((OdDb::TextHorzMode) mode);
}
Testing gives the following results:
0. Text Base
1. Text Bottom
2. Text Middle
3. Text Top
4. Quit
Entry the vertical mode:>2
Vertical mode = [2-Middle]
0. Text Left
1. Text Center
2. Text Right
3. Text Align
4. Text Middle
5. Text Fit
6. Quit
Entry the horizontal mode:>2
Horizontal mode = [2-Right]
Single-Line Text Alignment Properties
Example of Working with the Single-Line Text Object
Copyright © 2002 – 2020. Open Design Alliance. All rights reserved.
|