Please help...This is urgent.. |
Re: Need help in applyting color |
Re: Need help in applyting color SystemAdmin - Fri Nov 04 13:40:59 EDT 2011 |
Re: Need help in applyting color Joenar12 - Fri Nov 04 17:03:59 EDT 2011 You can set the color table in the RTF and use displayRichWithColor to display colored text. Try this code in a DXL Layout: string sFontTable = "{\\rtf1{\\colortbl;\\red255\\green0\\blue0;\\red0\\green255\\blue0;\\red0\\green0\\blue255;}" displayRichWithColor sFontTable "{\\b\\cf1 Hello in Bold Red}" displayRichWithColor sFontTable "{\\strike\\cf2 Hello in Strike Green}" displayRichWithColor sFontTable "{\\ul\\cf3 Hello in Underlined Blue}"
Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS
|
Re: Need help in applyting color Mathias Mamsch - Fri Nov 04 17:12:23 EDT 2011 You can set the color table in the RTF and use displayRichWithColor to display colored text. Try this code in a DXL Layout: string sFontTable = "{\\rtf1{\\colortbl;\\red255\\green0\\blue0;\\red0\\green255\\blue0;\\red0\\green0\\blue255;}" displayRichWithColor sFontTable "{\\b\\cf1 Hello in Bold Red}" displayRichWithColor sFontTable "{\\strike\\cf2 Hello in Strike Green}" displayRichWithColor sFontTable "{\\ul\\cf3 Hello in Underlined Blue}"
Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS
In my case some text is striked out and some underlined in same object.. How do i apply colors to these based on strikethrough's and underlines?? Below is the code i am using right now..I also attached a sample pic of my DOORS module. string sFontTable = "{\\rtf1{\\colortbl;\\red255\\green0\\blue0;\\red0\\green255\\blue0;\\red0\\green0\\blue255;}" displayRichWithColor sFontTable "{\\strike\\cf2 }" displayRichWithColor sFontTable "{\\ul\\cf3 }" if (obj."Object Heading" "" != "") { font(getCanvas, level(obj), HeadingsFont) displayRich(number(obj) " " obj."Object Heading" "") displayRichWithColor sFontTable ( " \\ul \\cf3 " (number(obj) " " obj."Object Heading" "" )) } if (obj."Object Text" "" != "") { font(getCanvas, level(obj),TextFont) displayRich(richTextWithOle(obj."Object Text")) } Attachments attachment_14700724_Capture.PNG |
Re: Need help in applyting color Joenar12 - Fri Nov 04 18:12:16 EDT 2011
Hmm ... That is not an easy problem. Manipulating richText is always hard. In this case one way would probably be to replace the richText keyword "\\strike" by "\\strike\\cf1" and the keyword "\\ul" by "\\ul\\cf2" ... however you would need to do some sanity checks to make sure that you do have an separator after the word and no backslash before the word. You could also iterate through the richText using the builtin functions and rebuild the string, but you might loose some formatting there. Note that you do not want the below function to work on OLE objects (it will run endlessly slow). So you might want to skip coloring for objects containing OLE. There are many optimization possibilities in below code, it just might give you a start. string sFontTable = "{\\rtf1{\\colortbl;\\red255\\green0\\blue0;\\red0\\green255\\blue0;\\red0\\green0\\blue255;}" string replace (string sSource, string sSearch, string sReplace, bool doReplace(string, int, int)) { int iLen = length sSource if (iLen == 0) return "" int iLenSearch = length(sSearch) if (iLenSearch == 0) { //raiseError ("Parameter error", "in strings.inc/replace: search string must not be empty") return "" } // read the first char for latter comparison -> speed optimization char firstChar = sSearch[0] Buffer s = create() int pos = 0, d1,d2; int i while (pos < iLen) { char ch = sSource[pos]; bool found = true if (ch != firstChar) {pos ++; s+= ch; continue} for (i = 1; i < iLenSearch; i++) if (sSource[pos+i] != sSearch[i]) { found = false; break } if (!found || !doReplace(sSource, pos, iLenSearch) ) {pos++; s+= ch; continue} s += sReplace pos += iLenSearch } string result = stringOf s delete s return result } // print richText (current Object)."Object Text" string test = "{\\rtf1\\ansi\\ansicpg1252\\deff0\\deflang1031{\\fonttbl{\\f0\\fnil\\fcharset0 Tahoma;}} \\viewkind4\\uc1\\pard\\f0\\fs20 This \\\\\\\\strike text is not \\\\striked but {\\\\\\strike dd}d is \\\\ul is also not \\\\\\\\ul. But this is \\strike striked \\strike0 and \\ul that\\ulnone is underlined!\\par }" bool checkTerminators(string s, int pos, int len) { // there is a backslash before our control word, check if it is escaped if (pos > 0 && s[pos-1] == '\\') { // count backslashes before the word int i, nr = 1; for (i = pos-1; s[i] == '\\'; i--) nr++ // check if it is unequal if (nr % 2 == 1) { // print "Unequal backslash count found at " pos "(" (s[i:pos+len]) ").\n" } else { // print "Equal backslash count found at " pos "(" s[i:pos+len] ").\n" return false } } // check for terminator after our search char term = s[pos+len] if (term != ' ' && term != '{' && term != '\\') { // print "No separator found at " pos " after '" s[pos:pos+len] "'\n"; return false } print "Replacing stuff at " pos "\n" return true } // print test test = replace(test, "\\strike", "\\strike\\cf1", checkTerminators) test = replace(test, "\\strike0", "\\strike0\\cf0", checkTerminators) test = replace(test, "\\strikenone", "\\strikenone\\cf0", checkTerminators) test = replace(test, "\\ul", "\\ul\\cf2", checkTerminators) test = replace(test, "\\ul0", "\\ul0\\cf0", checkTerminators) test = replace(test, "\\ulnone", "\\ulnone\\cf0", checkTerminators) // print test displayRichWithColor sFontTable test
Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS
|
Re: Need help in applyting color Mathias Mamsch - Fri Nov 04 19:35:09 EDT 2011
Hmm ... That is not an easy problem. Manipulating richText is always hard. In this case one way would probably be to replace the richText keyword "\\strike" by "\\strike\\cf1" and the keyword "\\ul" by "\\ul\\cf2" ... however you would need to do some sanity checks to make sure that you do have an separator after the word and no backslash before the word. You could also iterate through the richText using the builtin functions and rebuild the string, but you might loose some formatting there. Note that you do not want the below function to work on OLE objects (it will run endlessly slow). So you might want to skip coloring for objects containing OLE. There are many optimization possibilities in below code, it just might give you a start. string sFontTable = "{\\rtf1{\\colortbl;\\red255\\green0\\blue0;\\red0\\green255\\blue0;\\red0\\green0\\blue255;}" string replace (string sSource, string sSearch, string sReplace, bool doReplace(string, int, int)) { int iLen = length sSource if (iLen == 0) return "" int iLenSearch = length(sSearch) if (iLenSearch == 0) { //raiseError ("Parameter error", "in strings.inc/replace: search string must not be empty") return "" } // read the first char for latter comparison -> speed optimization char firstChar = sSearch[0] Buffer s = create() int pos = 0, d1,d2; int i while (pos < iLen) { char ch = sSource[pos]; bool found = true if (ch != firstChar) {pos ++; s+= ch; continue} for (i = 1; i < iLenSearch; i++) if (sSource[pos+i] != sSearch[i]) { found = false; break } if (!found || !doReplace(sSource, pos, iLenSearch) ) {pos++; s+= ch; continue} s += sReplace pos += iLenSearch } string result = stringOf s delete s return result } // print richText (current Object)."Object Text" string test = "{\\rtf1\\ansi\\ansicpg1252\\deff0\\deflang1031{\\fonttbl{\\f0\\fnil\\fcharset0 Tahoma;}} \\viewkind4\\uc1\\pard\\f0\\fs20 This \\\\\\\\strike text is not \\\\striked but {\\\\\\strike dd}d is \\\\ul is also not \\\\\\\\ul. But this is \\strike striked \\strike0 and \\ul that\\ulnone is underlined!\\par }" bool checkTerminators(string s, int pos, int len) { // there is a backslash before our control word, check if it is escaped if (pos > 0 && s[pos-1] == '\\') { // count backslashes before the word int i, nr = 1; for (i = pos-1; s[i] == '\\'; i--) nr++ // check if it is unequal if (nr % 2 == 1) { // print "Unequal backslash count found at " pos "(" (s[i:pos+len]) ").\n" } else { // print "Equal backslash count found at " pos "(" s[i:pos+len] ").\n" return false } } // check for terminator after our search char term = s[pos+len] if (term != ' ' && term != '{' && term != '\\') { // print "No separator found at " pos " after '" s[pos:pos+len] "'\n"; return false } print "Replacing stuff at " pos "\n" return true } // print test test = replace(test, "\\strike", "\\strike\\cf1", checkTerminators) test = replace(test, "\\strike0", "\\strike0\\cf0", checkTerminators) test = replace(test, "\\strikenone", "\\strikenone\\cf0", checkTerminators) test = replace(test, "\\ul", "\\ul\\cf2", checkTerminators) test = replace(test, "\\ul0", "\\ul0\\cf0", checkTerminators) test = replace(test, "\\ulnone", "\\ulnone\\cf0", checkTerminators) // print test displayRichWithColor sFontTable test
Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS
For some reason this did not work for me. I am attaching the screen shot. Thanks for all your help.. Will be waiting for your reply. Joe. Attachments attachment_14700746_Capture.PNG |
Re: Need help in applyting color Joenar12 - Fri Nov 04 20:39:01 EDT 2011 Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS |
Re: Need help in applyting color Mathias Mamsch - Fri Nov 04 21:38:44 EDT 2011 Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS I am not very fluent with DXL. I found the attached histcol.dxl in the \kitchen\History folder. It seems to do what is desired in this post. Would it be easy to modify so the newTextFont is displayed in BLUE and oldTextFont is displayed in RED? Hard-coding the colors would be the easiest for me to understand. Russ Attachments attachment_14702490_histcol.dxl |
Re: Need help in applyting color rmoskwa - Thu Nov 10 13:23:17 EST 2011 The history column script will make a colored richText diff from two non-richText strings. That is not the same problem, but maybe I got the intention of the user wrong. Regards, Mathias Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS |
Re: Need help in applyting color
hello, // DXL generated by DOORS traceability wizard on 11 November 2012. // Wizard version 2.0, DOORS version 9.3.0.7 pragma runLim, 0 const int indentStep = 360 Buffer indentBuff = create Buffer lineBuff = create lineBuff = "______________________" const Regexp LINKRegx = regexp2 "(parent2child|child2parent|See also)" string indentAllParagraphs(string s, bool addBullets, int addedIndent) { int numParas = 0 RichTextParagraph rtp indentBuff = s for rtp in s do { numParas++ Buffer t = create() t += rtp.text if (length(t) > 0 ) { bool hasBullet = rtp.isBullet int indentLev = rtp.indentLevel indentBuff = applyTextFormattingToParagraph(indentBuff, hasBullet, indentLev+addedIndent, numParas) } delete(t) } return (numParas == 0 ? "" : tempStringOf(indentBuff)) } int lines[4] = {0, 0, 0, 0} void adjustLines(int depth, showAtDepth) { int count for (count = 0; count < 4; count++) { while (lines[depth-1] < lines[count]) { if (depth == showAtDepth) displayRich("\\pard " " ") lines[depth-1]++ } } } void showIn(Object o, int depth) { Link l LinkRef lr ModName_ otherMod = null Module linkMod = null ModuleVersion otherVersion = null Object othero string s = null bool doneOne = false string linkModName = "*" for lr in all(o<-linkModName) do { otherMod = module (sourceVersion lr) if (!null otherMod) { if ((!isDeleted otherMod) && (null data(sourceVersion lr))) { load((sourceVersion lr),false) } } } for l in all(o<-linkModName) do { if(LINKRegx name(module l)) continue otherVersion = sourceVersion l otherMod = module(otherVersion) if (null otherMod || isDeleted otherMod) continue othero = source l if (null othero) {load(otherVersion,false)} othero = source l if (null othero || isDeleted othero) continue doneOne = true { displayRich tempStringOf applyTextFormattingToParagraph(lineBuff, false, (depth-1) * indentStep, 0) s = name(otherMod) if (isBaseline(otherVersion)) {s = s " [" versionString(otherVersion) "]"} s = indentAllParagraphs(s, false, (depth-1) * indentStep) if (s == "") {displayRich("\\pard " " ")} else { s = s "-" probeRichAttr_(othero,"Absolute Number", false) if( name(module(o)) == name(module(othero)) ) {s = "(" s ")"} //Apply color s = indentAllParagraphs(s, false, (depth-1) * indentStep) displayRich("\\pard " s) } } lines[depth-1] += 2 if ( depth < 4 ) {showIn(othero, depth+1)} } if (depth == 1) { ExternalLink extLink doneOne = false for extLink in o<-"" do { if (!doneOne) { displayRich("\\pard " "{\\b External Links:}") doneOne = true } } } } showIn(obj,1) delete LINKRegx delete indentBuff delete lineBuff |