mirror of
https://github.com/Open-Cascade-SAS/OCCT.git
synced 2026-06-24 05:08:04 +08:00
0030991: Draw Harness - ViewerTest::ParseColor() defines out-of-range alpha component
ViewerTest::ParseColor() - fixed alpha component defined as 255 for RGB-only input. Quantity_Color::ColorToHex() now rounds-up float values to closest integer. Quantity_ColorRGBA::ColorToHex() - added method formatting color into hex with alpha component consistent to Quantity_Color::ColorToHex() for RGB. vdrawtext command now uses ViewerTest::ParseColor() for parsing color argument, so that it accepts hex. vreadpixel command now has been extended with -hex argument for printing color in hex format. Commands XSetColor, XGetColor, XGetShapeColor, XGetAllColors, XAddColor, XRemoveColor, XFindColor, XUnsetColor, XGetInstanceColor, XSetInstanceColor have been corrected to properly report syntax input errors and to accept color names and hex (by reusing ViewerTest::ParseColor()).
This commit is contained in:
@@ -2388,42 +2388,17 @@ static int VDrawText (Draw_Interpretor& theDI,
|
||||
}
|
||||
else if (aParam == "-color")
|
||||
{
|
||||
if (anArgIt + 1 >= theArgsNb)
|
||||
Quantity_Color aColor;
|
||||
Standard_Integer aNbParsed = ViewerTest::ParseColor (theArgsNb - anArgIt - 1,
|
||||
theArgVec + anArgIt + 1,
|
||||
aColor);
|
||||
if (aNbParsed == 0)
|
||||
{
|
||||
std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n";
|
||||
std::cout << "Syntax error at '" << aParam << "'\n";
|
||||
return 1;
|
||||
}
|
||||
|
||||
TCollection_AsciiString aColor (theArgVec[anArgIt + 1]);
|
||||
Quantity_NameOfColor aNameOfColor = Quantity_NOC_BLACK;
|
||||
if (Quantity_Color::ColorFromName (aColor.ToCString(), aNameOfColor))
|
||||
{
|
||||
anArgIt += 1;
|
||||
aTextPrs->SetColor (aNameOfColor);
|
||||
continue;
|
||||
}
|
||||
else if (anArgIt + 3 >= theArgsNb)
|
||||
{
|
||||
std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n";
|
||||
return 1;
|
||||
}
|
||||
|
||||
TCollection_AsciiString aGreen (theArgVec[anArgIt + 2]);
|
||||
TCollection_AsciiString aBlue (theArgVec[anArgIt + 3]);
|
||||
if (!aColor.IsRealValue()
|
||||
|| !aGreen.IsRealValue()
|
||||
|| !aBlue.IsRealValue())
|
||||
{
|
||||
std::cout << "Error: wrong syntax at '" << aParam.ToCString() << "'.\n";
|
||||
return 1;
|
||||
}
|
||||
|
||||
const Graphic3d_Vec3d anRGB (aColor.RealValue(),
|
||||
aGreen.RealValue(),
|
||||
aBlue.RealValue());
|
||||
|
||||
aTextPrs->SetColor (Quantity_Color (anRGB.r(), anRGB.g(), anRGB.b(), Quantity_TOC_RGB));
|
||||
anArgIt += 3;
|
||||
anArgIt += aNbParsed;
|
||||
aTextPrs->SetColor (aColor);
|
||||
}
|
||||
else if (aParam == "-halign")
|
||||
{
|
||||
@@ -2598,42 +2573,17 @@ static int VDrawText (Draw_Interpretor& theDI,
|
||||
else if (aParam == "-subcolor"
|
||||
|| aParam == "-subtitlecolor")
|
||||
{
|
||||
if (anArgIt + 1 >= theArgsNb)
|
||||
Quantity_Color aColor;
|
||||
Standard_Integer aNbParsed = ViewerTest::ParseColor (theArgsNb - anArgIt - 1,
|
||||
theArgVec + anArgIt + 1,
|
||||
aColor);
|
||||
if (aNbParsed == 0)
|
||||
{
|
||||
std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n";
|
||||
std::cout << "Syntax error at '" << aParam << "'\n";
|
||||
return 1;
|
||||
}
|
||||
|
||||
TCollection_AsciiString aColor (theArgVec[anArgIt + 1]);
|
||||
Quantity_NameOfColor aNameOfColor = Quantity_NOC_BLACK;
|
||||
if (Quantity_Color::ColorFromName (aColor.ToCString(), aNameOfColor))
|
||||
{
|
||||
anArgIt += 1;
|
||||
aTextPrs->SetColorSubTitle (aNameOfColor);
|
||||
continue;
|
||||
}
|
||||
else if (anArgIt + 3 >= theArgsNb)
|
||||
{
|
||||
std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n";
|
||||
return 1;
|
||||
}
|
||||
|
||||
TCollection_AsciiString aGreen (theArgVec[anArgIt + 2]);
|
||||
TCollection_AsciiString aBlue (theArgVec[anArgIt + 3]);
|
||||
if (!aColor.IsRealValue()
|
||||
|| !aGreen.IsRealValue()
|
||||
|| !aBlue.IsRealValue())
|
||||
{
|
||||
std::cout << "Error: wrong syntax at '" << aParam.ToCString() << "'.\n";
|
||||
return 1;
|
||||
}
|
||||
|
||||
const Graphic3d_Vec3d anRGB (aColor.RealValue(),
|
||||
aGreen.RealValue(),
|
||||
aBlue.RealValue());
|
||||
|
||||
aTextPrs->SetColorSubTitle (Quantity_Color (anRGB.r(), anRGB.g(), anRGB.b(), Quantity_TOC_RGB));
|
||||
anArgIt += 3;
|
||||
anArgIt += aNbParsed;
|
||||
aTextPrs->SetColorSubTitle (aColor);
|
||||
}
|
||||
else if (aParam == "-2d")
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user