Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » U++ Library support » RichText,QTF,RTF... » String EncodeHtml (how to understand the vast majority of parameters of this function?)
String EncodeHtml [message #58732] Tue, 09 August 2022 19:57 Go to next message
BetoValle is currently offline  BetoValle
Messages: 203
Registered: September 2020
Location: Brasil Valinhos SP
Experienced Member
Hi,
it is very difficult for a new programmer to understand how to work with this function. Most of the difficulties I face are because I'm new to C++ and U++, but it really gets harder when the content is written for experts like I believe most who have established themselves here. They should write and think about those who have difficulty, because it is only with simpler examples that there is growth in the adoption of U++ . Sorry but this is a fact!

I'm about to choose the language if java or u++ to transcribe a program (delphi/desktop/windows) to web/linux (tomcat or skylark) where one of the tables has a field where medical patient history is stored, through "rtf" content that contains text , table and image.
I'm thinking of rewriting this field and storing html (or qtf mporting/exporting systematically)
So I need to understand the parameters of the function in reference.
for example with table in the code below


	String rtfContent;
rtfContent="{\\rtf1\\ansi\\ansicpg1252\\deff0{\\fonttbl{\\f0\\fnil Calibri;}{\\f1\\fnil\\fcharset0 Arial;}}
{\\colortbl ;\\red0\\green0\\blue0;\\red0\\green0\\blue128;}
\\viewkind4\\uc1\\trowd\\trgaph30\\trleft-30\\clbrdrt\\brdrw15\\brdrs\\clbrdrl\\brdrw15\\brdrs\\clbrdrb\\brdrw15\\brdrs\\clbrdrr\\brdrw15\\brdrs \\cellx647\\clbrdrt\\brdrw15\\brdrs\\clbrdrl\\brdrw15\\brdrs\\clbrdrb\\brdrw15\\brdrs\\clbrdrr\\brdrw15\\brdrs \\cellx1840\\clbrdrt\\brdrw15\\brdrs\\clbrdrl\\brdrw15\\brdrs\\clbrdrb\\brdrw15\\brdrs\\clbrdrr\\brdrw15\\brdrs \\cellx2372\\clbrdrt\\brdrw15\\brdrs\\clbrdrl\\brdrw15\\brdrs\\clbrdrb\\brdrw15\\brdrs\\clbrdrr\\brdrw15\\brdrs \\cellx3644\\clbrdrt\\brdrw15\\brdrs\\clbrdrl\\brdrw15\\brdrs\\clbrdrb\\brdrw15\\brdrs\\clbrdrr\\brdrw15\\brdrs \\cellx4112\\pard\\intbl\\cf1\\lang1046\\f0\\fs22\\cell 14/08/2017\\cell %\\cell 16/12/2019\\cell %\\cell\\row
\\intbl L1\\cell 0,656\\cell 58\\cell 0,684\\cell 69\\cell\\row
\\intbl L2\\cell 0,663\\cell 55\\cell 0,652\\cell 63\\cell\\row
\\intbl L3\\cell 0,602\\cell 50\\cell 0,612\\cell 56\\cell\\row
\\intbl L4\\cell 0,693\\cell 58\\cell 0,609\\cell 57\\cell\\row
\\intbl colo E\\cell 0,719\\cell 69\\cell 0,625\\cell 74\\cell\\row
\\intbl troc\\cell\\cell\\cell 0,555\\cell 75\\cell\\row
\\intbl radio\\cell 0,747\\cell 84\\cell 0,591\\cell 85\\cell\\row
\\pard\\cf2\\b\\f1\\fs16 CD= Manter com Prolia, visto haver ainda risco de fratura.\\par
}";

  String result = EncodeHtml( rtfContent , Index<String>& css,
                  const VectorMap<String, String>& links,
                  const VectorMap<String, String>& labels,
                  HtmlObjectSaver& object_saver, Zoom z,
                  const VectorMap<String, String>& escape);
  
    Cout() << result << EOL;



how to initialize with each of the parameters below to introduce them in the function to return html content?

Index<String>& css,
const VectorMap<String, String>& links,
const VectorMap<String, String>& labels,
HtmlObjectSaver& object_saver,
Zoom z,
const VectorMap<String, String>& escape

Thanks!

Re: String EncodeHtml [message #58733 is a reply to message #58732] Tue, 09 August 2022 20:52 Go to previous messageGo to next message
Klugier is currently offline  Klugier
Messages: 1077
Registered: September 2012
Location: Poland, Kraków
Senior Contributor
Hello BetoValle,

I will do not tell you how to use this function, but I agree that it should be simple. Optimally any public API function/method should posses up to three parameters. Thanks to that it will be easy to use and users will do not complain about difficulties. I think in this case this function could be refator to HtmlEncoder class with parameters provided as separate method. So, it can look like this:
// Basic example:
auto results = HtmlEncoder(rtfContent).Encode();

// With parameters:
auto results = HtmlEncoder(rtfContent).Css({}).Encode();


Thanks for feedback, I know that there are some places in U++ framework when API is not user friendly and it should be reworked. I hope somebody will answer to your question how to use this over complicated function!

Klugier


U++ - one framework to rule them all.
Re: String EncodeHtml [message #58735 is a reply to message #58732] Thu, 11 August 2022 09:11 Go to previous messageGo to next message
jjacksonRIAB is currently offline  jjacksonRIAB
Messages: 221
Registered: June 2011
Experienced Member
Haven't messed with this method before but I gave it a shot.

Problem #1 is you're using a String when the data type for the first parameter is RichText. If you want to convert a String to RichText you need to Add RichEdit to your project and call ParseRTF on it.

I loaded it as a .brc file but that's not relevant:

#include <Core/Core.h>
#include <RichText/RichText.h>
#include <RichEdit/RichEdit.h>

#include "test.brc"

using namespace Upp;

CONSOLE_APP_MAIN {
    String rtfContent(std_tmpl_vfk, std_tmpl_vfk_length);
    RichText rt = ParseRTF(rtfContent);
    
    // Output parameters
    Index<String> css;
    VectorMap<String, String> links;
    VectorMap<String, String> labels;

    // Context, I'm assuming
    HtmlObjectSaver saver;
    
    String result = EncodeHtml(rt, css, links, labels, saver);
    
    Cout() << result;

    // To get the css
    Cout() << AsCss(css);
}


I don't know what the deal is with your .rtf string but it doesn't work. I have been able to render other rtf documents using this method though.
EDIT
Never mind, you didn't terminate each line as such:

	String rtfContent =
	"{\\rtf1\\ansi\\ansicpg1252\\deff0{\\fonttbl{\\f0\\fnil Calibri;}{\\f1\\fnil\\fcharset0 Arial;}}\n"
	"{\\colortbl ;\\red0\\green0\\blue0;\\red0\\green0\\blue128;}\n"
	"\\viewkind4\\uc1\\trowd\\trgaph30\\trleft-30\\clbrdrt\\brdrw15\\brdrs\\clbrdrl\\brdrw15\\brdrs\\clbrdrb\\brdrw15\\brdrs\\clbrdrr\\brdrw15\\brdrs \\cellx647\\clbrdrt\\brdrw15\\brdrs\\clbrdrl\\brdrw15\\brdrs\\clbrdrb\\brdrw15\\brdrs\\clbrdrr\\brdrw15\\brdrs \\cellx1840\\clbrdrt\\brdrw15\\brdrs\\clbrdrl\\brdrw15\\brdrs\\clbrdrb\\brdrw15\\brdrs\\clbrdrr\\brdrw15\\brdrs \\cellx2372\\clbrdrt\\brdrw15\\brdrs\\clbrdrl\\brdrw15\\brdrs\\clbrdrb\\brdrw15\\brdrs\\clbrdrr\\brdrw15\\brdrs \\cellx3644\\clbrdrt\\brdrw15\\brdrs\\clbrdrl\\brdrw15\\brdrs\\clbrdrb\\brdrw15\\brdrs\\clbrdrr\\brdrw15\\brdrs \\cellx4112\\pard\\intbl\\cf1\\lang1046\\f0\\fs22\\cell 14/08/2017\\cell %\\cell 16/12/2019\\cell %\\cell\\row\n"
	"\\intbl L1\\cell 0,656\\cell 58\\cell 0,684\\cell 69\\cell\\row\n"
	"\\intbl L2\\cell 0,663\\cell 55\\cell 0,652\\cell 63\\cell\\row\n"
	"\\intbl L3\\cell 0,602\\cell 50\\cell 0,612\\cell 56\\cell\\row\n"
	"\\intbl L4\\cell 0,693\\cell 58\\cell 0,609\\cell 57\\cell\\row\n"
	"\\intbl colo E\\cell 0,719\\cell 69\\cell 0,625\\cell 74\\cell\\row\n"
	"\\intbl troc\\cell\\cell\\cell 0,555\\cell 75\\cell\\row\n"
	"\\intbl radio\\cell 0,747\\cell 84\\cell 0,591\\cell 85\\cell\\row\n"
	"\\pard\\cf2\\b\\f1\\fs16 CD= Manter com Prolia, visto haver ainda risco de fratura.\\par\n"
	"}\n";



You might be better off using raw string literals: https://www.geeksforgeeks.org/raw-string-literal-c/ or putting your rtf in a separate file in your project, loading it from a .brc like I did: https://www.ultimatepp.org/srcdoc$Core$BRC_en-us.html.

[Updated on: Thu, 11 August 2022 12:25]

Report message to a moderator

Re: String EncodeHtml [message #58737 is a reply to message #58735] Thu, 11 August 2022 14:45 Go to previous messageGo to next message
BetoValle is currently offline  BetoValle
Messages: 203
Registered: September 2020
Location: Brasil Valinhos SP
Experienced Member
Hi jjacksonRIAB!
Tanks! your recommendation is very good. Every theory with a good example becomes clearer to help understanding!


CONSOLE_APP_MAIN   
{
	String x2 = "{\\rtf1\\ansi\\deff0{\\fonttbl{\\f0\\froman\\fprq2\\fcharset0 Times New Roman;}{\\f1\\fswiss\\fprq2\\fcharset0 Arial;}}";
	x2 += "\\viewkind4\\uc1\\pard\\lang1046\\f0\\fs24 Refere que teve mal estar e n\\'e3o conseguia dormir com Amitriptilina, Terminou gabapentina 900 mg 2X/dia. ";
	x2 += "\\par Exames :Vit D= 47,4 e PTH= 47 calcemia= 9,1; ";
	x2 += "\\par \\trowd\\trgaph70\\trleft-15\\cellx592\\cellx1552\\cellx1972\\cellx2792\\cellx3172\\pard\\intbl\\f1\\fs20 DMO\\cell 2009\\cell %\\cell 2011\\cell %\\cell\\f0\\row";
	x2 += "\\f1\\trowd\\trgaph70\\trleft-15\\cellx592\\cellx1552\\cellx1972\\cellx2792\\cellx3172\\intbl L1\\cell 0,824\\cell 73\\cell 0,79\\cell 70\\cell\\f0\\row";
	x2 += "\\f1\\trowd\\trgaph70\\trleft-15\\cellx592\\cellx1552\\cellx1972\\cellx2792\\cellx3172\\intbl L2\\cell 0,858\\cell 71\\cell 0,922\\cell 77\\cell\\f0\\row";
	x2 += "\\f1\\trowd\\trgaph70\\trleft-15\\cellx592\\cellx1552\\cellx1972\\cellx2792\\cellx3172\\intbl L3\\cell 0,904\\cell 75\\cell 0,914\\cell 76\\cell\\f0\\row";
	x2 += "\\f1\\trowd\\trgaph70\\trleft-15\\cellx592\\cellx1552\\cellx1972\\cellx2792\\cellx3172\\intbl L4\\cell 0,861\\cell 72\\cell 0,89\\cell 74\\cell\\f0\\row";
	x2 += "\\f1\\trowd\\trgaph70\\trleft-15\\cellx592\\cellx1552\\cellx1972\\cellx2792\\cellx3172\\intbl colo\\cell 0,671\\cell 68\\cell 0,667\\cell 64\\cell\\f0\\row";
	x2 += "\\f1\\trowd\\trgaph70\\trleft-15\\cellx592\\cellx1552\\cellx1972\\cellx2792\\cellx3172\\intbl troc\\cell 0,749\\cell 95\\cell 0,515\\cell 61\\cell\\f0\\row";
	x2 += "\\pard\\fs24 RX= desmineraliza\\'e7\\'e3o \\'f3ssea localizada em grande trocanter, sem les\\'f4es l\\'edticas.";
	x2 += "\\par Cd=Manter Actonel 150.  Depura 5 gotas por dia. oscal 2X/dia  + Gabapentina 900mg 2X/dia. Manter Amitriptilina 25 mg pela manh\\'e3. ";
	x2 += "\\par";
	x2 += "\\par }";
	
	RichText rt2 = ParseRTF ( x2 );
	
	Index<String> css2; 
	const VectorMap<String, String> links2; 
	VectorMap<String, String> labels2;
	HtmlObjectSaver saver2;
	
	String y = EncodeHtml ( rt2, css2, links2, labels2, saver2 );
	
	Cout() << "------------------result---------------" << EOL;
	Cout() <<  y << EOL;
	Cout() << "------------------CSS------------------" << EOL;
        Cout() << AsCss(css2);

}





rtf format reference
  • Attachment: demo.png
    (Size: 131.70KB, Downloaded 115 times)
icon14.gif  Re: String EncodeHtml [message #58738 is a reply to message #58737] Thu, 11 August 2022 14:59 Go to previous message
BetoValle is currently offline  BetoValle
Messages: 203
Registered: September 2020
Location: Brasil Valinhos SP
Experienced Member
I also tanks to Klugier and Mirek!
Previous Topic: Skipping footer/header and page numbering...
Goto Forum:
  


Current Time: Sat May 25 11:05:25 CEST 2024

Total time taken to generate the page: 0.01371 seconds