Topic
  • 10 replies
  • Latest Post - ‏2014-03-03T19:16:37Z by strathglass
thomas.abdoul
thomas.abdoul
2 Posts

Pinned topic concatenate object Text with rtf

‏2012-09-12T09:46:26Z |
Hello,

I'm trying to concatenate Object Text of several objects . But i want to keep the rtf formating of each objects. I didn't sucess. What i done is concatenating rtf extracted from each object wich didn't work because i repeat the rtf heading like this simple exemple:

{\rtf1\ansi\ansicpg1252\deff0\deflang1036{\fonttbl{\f0\fnil\fcharset0 Tahoma;}{\f1\fnil\fcharset2 Symbol;}}
{\*\generator Msftedit 5.41.21.2500;}\viewkind4\uc1\pard\f0\fs20 ligne 1\par
\pard{\pntext\f1\'B7\tab}{\*\pn\pnlvlblt\pnf1\pnindent0{\pntxtb\'B7}}ligne2\par
}
{\rtf1\ansi\ansicpg1252\deff0\deflang1036{\fonttbl{\f0\fnil\fcharset0 Tahoma;}{\f1\fnil\fcharset2 Symbol;}}
{\*\generator Msftedit 5.41.21.2500;}\viewkind4\uc1\pard\f0\fs20 ligne 1\par
\pard{\pntext\f1\'B7\tab}{\*\pn\pnlvlblt\pnf1\pnindent0{\pntxtb\'B7}}ligne2\par
}

Someone have a solution?

Thanks,
Updated on 2012-09-14T20:04:12Z at 2012-09-14T20:04:12Z by Mathias Mamsch
  • Mathias Mamsch
    Mathias Mamsch
    1967 Posts

    Re: concatenate object Text with rtf

    ‏2012-09-12T09:55:07Z  
    The funny thing is, that DOORS will actually allow you to do that (i.e. just concatenate the richText, write that to an attribute or display it) and still show a valid result. So it should be fine, if you just concat the richTexts and write them back to the object. If you want valid RTF then you would need to use richTextFragment, to cut off the header, BUT this will also cut away the font table. So to make a function that would give you a valid richText, you would need to create a new font table from the concatenated richTexts and translate the font statements in one of the richText. Total overkill, so I would suggest you stay with the concatenated richTexts.

    There are several examples in the forum for concatenating richText. Use the search to find code examples. Hope this helps, regards, Mathias


    Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS
  • thomas.abdoul
    thomas.abdoul
    2 Posts

    Re: concatenate object Text with rtf

    ‏2012-09-12T13:20:39Z  
    The funny thing is, that DOORS will actually allow you to do that (i.e. just concatenate the richText, write that to an attribute or display it) and still show a valid result. So it should be fine, if you just concat the richTexts and write them back to the object. If you want valid RTF then you would need to use richTextFragment, to cut off the header, BUT this will also cut away the font table. So to make a function that would give you a valid richText, you would need to create a new font table from the concatenated richTexts and translate the font statements in one of the richText. Total overkill, so I would suggest you stay with the concatenated richTexts.

    There are several examples in the forum for concatenating richText. Use the search to find code examples. Hope this helps, regards, Mathias


    Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS
    Thank you Mathias!!

    In fact the solution was strangely simple...Indeed i had just to concatenate the richtext extracted from the object text and put it in my new object. I think i had errors in manipulation between string and richtexts extracts. So i have just to do a thing like:

    string s1 = richText o1."Object Text"
    string s2 = richText o2."Object Text"
    string s3 = richText s1 "\\par" s2
    myNewObject."Object Text" richText s3

    Thank you for your help!
  • llandale
    llandale
    2972 Posts

    Re: concatenate object Text with rtf

    ‏2012-09-12T18:10:59Z  
    Thank you Mathias!!

    In fact the solution was strangely simple...Indeed i had just to concatenate the richtext extracted from the object text and put it in my new object. I think i had errors in manipulation between string and richtexts extracts. So i have just to do a thing like:

    string s1 = richText o1."Object Text"
    string s2 = richText o2."Object Text"
    string s3 = richText s1 "\\par" s2
    myNewObject."Object Text" richText s3

    Thank you for your help!
    • use richTextWithOle() to get the entire contents.
    • Get out of the habit of concatenating large strings. Try this:
    Buffer bufTemp = create()
    bufTemp = richTextWithOle(o1."Object Text")
    bufTemp += "\\par "
    bufTemp += richTextWithOle(o2."Object Text")
    myNewObject."Object Text" = richText(tempStringOf(bufTemp))
    delete(bufTemp)

    -Louie
  • Mathias Mamsch
    Mathias Mamsch
    1967 Posts

    Re: concatenate object Text with rtf

    ‏2012-09-12T21:17:01Z  
    • llandale
    • ‏2012-09-12T18:10:59Z
    • use richTextWithOle() to get the entire contents.
    • Get out of the habit of concatenating large strings. Try this:
    Buffer bufTemp = create()
    bufTemp = richTextWithOle(o1."Object Text")
    bufTemp += "\\par "
    bufTemp += richTextWithOle(o2."Object Text")
    myNewObject."Object Text" = richText(tempStringOf(bufTemp))
    delete(bufTemp)

    -Louie

    Lets do that right, shall we? ;-)
     

    Buffer bufResult = create()
       Buffer bufTemp   = create() 
       bufResult = richTextWithOle(o1."Object Text")
       bufResult += "\\par "
       bufTemp = richTextWithOle(o2."Object Text")
       combine(bufResult, bufTemp, 0) 
       myNewObject."Object Text" = richText bufResult
       delete bufTemp
       delete bufResult
    

     


    The += operator takes only strings, meaning you will have your big fat richTextWithOle going right to the string table. Also do not do the tempStringOf thing, because richText(string) also returns a big fat string for your string table. If you do it like above you will use RTF_buffer__ types, which (hopefully) come without string table pollutions. Regards, Mathias

     

     

     


    Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS

     

     

    Updated on 2014-01-06T21:31:11Z at 2014-01-06T21:31:11Z by JAntley
  • llandale
    llandale
    2972 Posts

    Re: concatenate object Text with rtf

    ‏2012-09-13T19:37:58Z  

    Lets do that right, shall we? ;-)
     

    <pre class="javascript dw" data-editor-lang="js" data-pbcklang="javascript" dir="ltr">Buffer bufResult = create() Buffer bufTemp = create() bufResult = richTextWithOle(o1."Object Text") bufResult += "\\par " bufTemp = richTextWithOle(o2."Object Text") combine(bufResult, bufTemp, 0) myNewObject."Object Text" = richText bufResult delete bufTemp delete bufResult </pre>

     


    The += operator takes only strings, meaning you will have your big fat richTextWithOle going right to the string table. Also do not do the tempStringOf thing, because richText(string) also returns a big fat string for your string table. If you do it like above you will use RTF_buffer__ types, which (hopefully) come without string table pollutions. Regards, Mathias

     

     

     


    Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS

     

     

    I was just testing you!
  • Peter_Albert
    Peter_Albert
    250 Posts

    Re: concatenate object Text with rtf

    ‏2012-09-14T07:30:38Z  

    Lets do that right, shall we? ;-)
     

    <pre class="javascript dw" data-editor-lang="js" data-pbcklang="javascript" dir="ltr">Buffer bufResult = create() Buffer bufTemp = create() bufResult = richTextWithOle(o1."Object Text") bufResult += "\\par " bufTemp = richTextWithOle(o2."Object Text") combine(bufResult, bufTemp, 0) myNewObject."Object Text" = richText bufResult delete bufTemp delete bufResult </pre>

     


    The += operator takes only strings, meaning you will have your big fat richTextWithOle going right to the string table. Also do not do the tempStringOf thing, because richText(string) also returns a big fat string for your string table. If you do it like above you will use RTF_buffer__ types, which (hopefully) come without string table pollutions. Regards, Mathias

     

     

     


    Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS

     

     

    > The += operator takes only strings

    Really? The DXL help lists three append operators for Buffers:

    Buffer b += string s
    Buffer b += char c
    Buffer b += Buffer b

    and so far I thought appending a Buffer would be safe, memory-wise. Is that not the case?

    Cheers,

    Peter
  • Mathias Mamsch
    Mathias Mamsch
    1967 Posts

    Re: concatenate object Text with rtf

    ‏2012-09-14T09:39:55Z  
    > The += operator takes only strings

    Really? The DXL help lists three append operators for Buffers:

    Buffer b += string s
    Buffer b += char c
    Buffer b += Buffer b

    and so far I thought appending a Buffer would be safe, memory-wise. Is that not the case?

    Cheers,

    Peter

    Sorry I stand corrected. I just tested it and
     

    #include <src/test/core/petools.inc>
    #include <src/test/core/stringTable.inc>
     
    print "Start of the program: \n"
    printStringTable(); print "\n"
     
    Buffer buf = create() 
    Buffer buf2 = create() 
     
    print "After Creating Buffers: \n"
    printStringTable(); print "\n"
     
    buf += "Hello"
     
    print "After Adding a String using +=\n"
    printStringTable(); print "\n"
     
    buf2 = "World!"
    buf += buf2
     
    print "After Adding a Buffer using +=\n"
    printStringTable(); print "\n"
     
    buf2 = "ORLY?!"
    buf2 += "YARLY!1"
    buf += tempStringOf buf2
     
    print "After Adding a Buffer using +=  tempStringOf\n"
    printStringTable(); print "\n"
     
    buf2 = "ZOMFG!"
    buf2 += "WHUD?"
    buf += stringOf buf2
    print "After Adding a Buffer using +=  stringOf\n"
    printStringTable(); print "\n"
    

     


    The code above produces this output:

     

     

     

    Start of the program: 
    Count = 16732
    Clashes = 2456
     
    After Creating Buffers: 
    Count = 16732
    Clashes = 2456
     
    After Adding a String using +=
    Count = 16732
    Clashes = 2456
     
    After Adding a Buffer using +=
    Count = 16732
    Clashes = 2456
     
    After Adding a Buffer using +=  tempStringOf
    Count = 16732
    Clashes = 2456
     
    After Adding a Buffer using +=  stringOf
    Count = 16733
    Clashes = 2457
    



    So neither Buffer += tempStringOf Buffer nor Buffer += Buffer produce a string table residual. If anyone is interested in the stringTable code, i can post that. Regards, Mathias



     

     

     

     


    Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS

     

     

    Updated on 2014-01-06T21:32:24Z at 2014-01-06T21:32:24Z by JAntley
  • Peter_Albert
    Peter_Albert
    250 Posts

    Re: concatenate object Text with rtf

    ‏2012-09-14T10:28:09Z  

    Sorry I stand corrected. I just tested it and
     

    <pre class="javascript dw" data-editor-lang="js" data-pbcklang="javascript" dir="ltr">#include <src/test/core/petools.inc> #include <src/test/core/stringTable.inc> print "Start of the program: \n" printStringTable(); print "\n" Buffer buf = create() Buffer buf2 = create() print "After Creating Buffers: \n" printStringTable(); print "\n" buf += "Hello" print "After Adding a String using +=\n" printStringTable(); print "\n" buf2 = "World!" buf += buf2 print "After Adding a Buffer using +=\n" printStringTable(); print "\n" buf2 = "ORLY?!" buf2 += "YARLY!1" buf += tempStringOf buf2 print "After Adding a Buffer using += tempStringOf\n" printStringTable(); print "\n" buf2 = "ZOMFG!" buf2 += "WHUD?" buf += stringOf buf2 print "After Adding a Buffer using += stringOf\n" printStringTable(); print "\n" </pre>

     


    The code above produces this output:

     

     

     

    <pre class="javascript dw" data-editor-lang="js" data-pbcklang="javascript" dir="ltr">Start of the program: Count = 16732 Clashes = 2456 After Creating Buffers: Count = 16732 Clashes = 2456 After Adding a String using += Count = 16732 Clashes = 2456 After Adding a Buffer using += Count = 16732 Clashes = 2456 After Adding a Buffer using += tempStringOf Count = 16732 Clashes = 2456 After Adding a Buffer using += stringOf Count = 16733 Clashes = 2457 </pre>



    So neither Buffer += tempStringOf Buffer nor Buffer += Buffer produce a string table residual. If anyone is interested in the stringTable code, i can post that. Regards, Mathias



     

     

     

     


    Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS

     

     

    > If anyone is interested in the stringTable code, i can post that

    I am :-)
  • Mathias Mamsch
    Mathias Mamsch
    1967 Posts

    Re: concatenate object Text with rtf

    ‏2012-09-14T20:04:12Z  
    > If anyone is interested in the stringTable code, i can post that

    I am :-)
    Well here you go: http://www.ibm.com/developerworks/forums/thread.jspa?threadID=455488&tstart=0

    Have fun, Regards, Mathias

    Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS
  • strathglass
    strathglass
    106 Posts

    Re: concatenate object Text with rtf

    ‏2014-03-03T19:16:37Z  

    Lets do that right, shall we? ;-)
     

    <pre class="javascript dw" data-editor-lang="js" data-pbcklang="javascript" dir="ltr">Buffer bufResult = create() Buffer bufTemp = create() bufResult = richTextWithOle(o1."Object Text") bufResult += "\\par " bufTemp = richTextWithOle(o2."Object Text") combine(bufResult, bufTemp, 0) myNewObject."Object Text" = richText bufResult delete bufTemp delete bufResult </pre>

     


    The += operator takes only strings, meaning you will have your big fat richTextWithOle going right to the string table. Also do not do the tempStringOf thing, because richText(string) also returns a big fat string for your string table. If you do it like above you will use RTF_buffer__ types, which (hopefully) come without string table pollutions. Regards, Mathias

     

     

     


    Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS

     

     

    Coming back to this older thread...

    I wanted to do something similar, but output rich text to the clipboard.

    For some reason, it seems to loose the bullets from my objects (even when I explicitly tried adding "true,true" to end of setRichClip).

    Other RTF formatting comes out OK (e.g. italics, bold, and indenting level).

    Any ideas on how to fix? (I don't know anything about font tables, so the example code just uses something from a DXL help example.)

     

    void appendOLEoTxt(Object o,Buffer b)
    {
        Buffer bTmp=create()
            bTmp = richTextWithOle(o."Object Text")
            b += "\\par "
            combine(b,bTmp,0) 
            delete bTmp
    }
    
    Object o81=object(81,current Module)
    Object o83=object(83,current Module)
    Object o93=object(93,current Module)
    
    Buffer bufResult = create()
    bufResult = richTextWithOle(o81."Object Text")
    
    appendOLEoTxt(o83,bufResult)
    appendOLEoTxt(o93,bufResult)
    
    string fontTable = "\\deff0{\\fonttbl {\\f1 Times New Roman;}}" 
    setRichClip(bufResult,"Normal",fontTable)
    
    delete bufResult