Example of -csspath option

  • It was noted in changes for 5.22 that there is an option to specify a style sheet.

    "-csspath:"..." can be used to specify a CSS style for loading and saving"

    I couldn't find an example of where this is done and what we should pass to it.

    Here is what I tried:

    FPaintEngine.Memo.TextLoadFormat:=FPaintEngine.Memo.TextLoadFormat+' -csspath:"\ReportStyleSheets\ReportStyles.css"';

    Do I need to send the full path, or will a relative path do?

    Do I need to add a link to it in a header in the html, or not?

    Thanks!

    • Offizieller Beitrag

    If you have a stylesheet in CSS format you can load it with

    WPRichText1.LoadFromFile( 'test.htm', true, 'AUTO-csspath:"style.css"')

    This is test,html

    HTML
    <html>
    <head>
    <link rel=stylesheet href="any_name.css">
    </head>
    <body>
    <div class="Normal">Normal Line</div>
    <div class="Text">Text Line</div>
    <div class="Text">Text Line</div>
    <div class="Text">Text Line</div>
    </body></html>

    This is style.css

    Code
    .Normal{text-indent:0.00in;line-height:115%;text-align:left;vertical-align:top;font-family:'Calibri';font-size:11.00pt;margin:0.00in 0.00in 0.14in 0.00in;}
    .Text{text-indent:0.00in;text-align:left;vertical-align:top;font-size:12.00pt;margin:0.00in;}
    div{font-family:'Arial';font-size:11.00pt;}

    If the file any_name.css actually exists, it is loaded instead of style.css, unless you modify the behavior using the event OnRequestHTTPString

    Code
    procedure TForm1.WPRichText1RequestHTTPString(
    RTFData: TWPRTFDataCollectionBase; Reader: TWPCustomTextReader;
    const LoadPath, url: string; var LoadedString: AnsiString; var Ok: Boolean);

    If you want to load a style sheet to your HTML data you do not need the csspath option. Simply load the CSS into your paragraph style collection using SetCSS. If you saved the styles in WPCSS format you can also use ParStyles.LoadFromFile.

    Code
    WPRichText1.Clear;
    WPRichText1.ParStyles.SetCSS(
    '.Normal{font-family:"Calibri";font-size:11.00pt;}' + #10+
    '.Text{font-family:"Arial";font-size:10.00pt;}');
    WPRichText1.LoadFromFile( 'test.html', false );