trichview.com Forum Index trichview.com
TRichView support forums
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Combining HypertextLinks and TextFormating in TRichviewEdt

 
Post new topic   Reply to topic    trichview.com Forum Index -> Support
View previous topic :: View next topic  
Author Message
ENatter



Joined: 12 Jul 2010
Posts: 3

PostPosted: Mon Jul 12, 2010 4:11 pm    Post subject: Combining HypertextLinks and TextFormating in TRichviewEdt Reply with quote

Since I wan't to integrate in my Delphi Application a TRichViewEdit, that allows to integrate Hyperlinks like in the Demo "CreateHyperlink" and TextFormating (Bold, Italic, Underline) like in the Demo "Editor 2" I got to the Point where the declaration of constant redefine actions:

Code:

const
  TEXT_BOLD       = 1;
  TEXT_ITALIC     = 2;
  TEXT_UNDERLINE  = 3;
  CONVERT_TO_HYPERTEXT    = 1;
  CONVERT_TO_NONHYPERTEXT = 2;


So every Bold is going to be a link. Probably solution is easy but currently I don't have a clue?!

Please help....
Back to top
View user's profile Send private message
Sergey Tkachenko
Site Admin


Joined: 27 Aug 2005
Posts: 6599

PostPosted: Mon Jul 12, 2010 5:03 pm    Post subject: Reply with quote

How to combine these two demos.
1) All constants used for calls of ApplyStyleConversion must be unique.
Since "Editor 2" already uses constants from 1 to 8:
Code:
  TEXT_BOLD       = 1;
  TEXT_ITALIC     = 2;
  TEXT_UNDERLINE  = 3;
  TEXT_APPLYFONTNAME  = 4;
  TEXT_APPLYFONT      = 5;
  TEXT_APPLYFONTSIZE  = 6;
  TEXT_COLOR      = 7;
  TEXT_BACKCOLOR  = 8;

redefine
Code:
  CONVERT_TO_HYPERTEXT    = 9;
  CONVERT_TO_NONHYPERTEXT = 10;


2) Add these new constants to TForm1.rveStyleConversion (of "Editor 2" demo). I copied code from TForm1.GetNonHypertextStyleNo and TForm1.GetHypertextStyleNo directly in this event:
Code:
procedure TForm1.rveStyleConversion(Sender: TCustomRichViewEdit; StyleNo,
  UserData: Integer; AppliedToText: Boolean; var NewStyleNo: Integer);
var FontInfo: TFontInfo;
begin
  FontInfo := TFontInfo.Create(nil);
  try
    FontInfo.Assign(rvs.TextStyles[StyleNo]);
    case UserData of
      TEXT_BOLD:
        if btnBold.Down then
          FontInfo.Style := FontInfo.Style+[fsBold]
        else
          FontInfo.Style := FontInfo.Style-[fsBold];
      TEXT_ITALIC:
        if btnItalic.Down then
          FontInfo.Style := FontInfo.Style+[fsItalic]
        else
          FontInfo.Style := FontInfo.Style-[fsItalic];
      TEXT_UNDERLINE:
        if btnUnderline.Down then
          FontInfo.Style := FontInfo.Style+[fsUnderline]
        else
          FontInfo.Style := FontInfo.Style-[fsUnderline];
      TEXT_APPLYFONTNAME:
        FontInfo.FontName := FontName;
      TEXT_APPLYFONTSIZE:
        FontInfo.Size     := FontSize;
      TEXT_APPLYFONT:
        FontInfo.Assign(fd.Font);
      TEXT_COLOR:
        FontInfo.Color := cd.Color;
      TEXT_BACKCOLOR:
        FontInfo.BackColor := cd.Color;
      CONVERT_TO_HYPERTEXT:
        begin
          FontInfo.Color := clBlue;
          FontInfo.Style := FontInfo.Style + [fsUnderline];
          FontInfo.Jump  := True;
        end;
      CONVERT_TO_NONHYPERTEXT:
        begin
          FontInfo.Color := clWindowText;
          FontInfoStyle := FontInfo.Style - [fsUnderline];
          FontInfo.Jump  := False;
        end;

      // add your code here....
    end;
    NewStyleNo := rvs.TextStyles.FindSuchStyle(StyleNo,FontInfo,RVAllFontInfoProperties);
    if NewStyleNo=-1 then begin
      rvs.TextStyles.Add;
      NewStyleNo := rvs.TextStyles.Count-1;
      rvs.TextStyles[NewStyleNo].Assign(FontInfo);
      rvs.TextStyles[NewStyleNo].Standard := False;
    end;
  finally
    FontInfo.Free;
  end;
end;

Now you can use commands from "CreateHyperlink" demo to add hyperlinks.
Back to top
View user's profile Send private message Visit poster's website
ENatter



Joined: 12 Jul 2010
Posts: 3

PostPosted: Wed Jul 14, 2010 9:21 am    Post subject: Reply with quote

Thanks a lot, this solves the Issue. But I've encountered two additional things.

1. While exporting with SaveHTML I always get complete HTML-Files. Means I also have a HTML Head and Body Tags. But I only wan't the pure HTML-Code between the BODY-Tags. I wrote a small Routine cropping the rest off, but isn't there a chance to get only the Part converted without HTML around it?

2. When adding a link like in the Example, and exporting it as HTML (see 1.) I have the Links formated Blue and Underlined. I understand that these Formating are neccessary in Editor to display Links, but oi they have to get exported??
Back to top
View user's profile Send private message
Sergey Tkachenko
Site Admin


Joined: 27 Aug 2005
Posts: 6599

PostPosted: Wed Jul 14, 2010 4:49 pm    Post subject: Reply with quote

1) Include rvsoMiddleOnly in the Options parameter of SaveHTML/SaveHTMLEx

2) The current version of TRichView always export all font attributes of hyperlinks. Probably, an option will be added in future.
Back to top
View user's profile Send private message Visit poster's website
ENatter



Joined: 12 Jul 2010
Posts: 3

PostPosted: Thu Jul 15, 2010 11:01 am    Post subject: Reply with quote

To 1: Thanks a lot he solution. Only on thing, while editing you get a font tag (font size="2" face="Microsoft San Serif" into the generated HTML. Sure this is the font used in the Edit, but I don't think that this should be in the final HTML

To 2: Well I think for a proper HTML-Export this shouldn't be in that way
Back to top
View user's profile Send private message
Sergey Tkachenko
Site Admin


Joined: 27 Aug 2005
Posts: 6599

PostPosted: Thu Jul 15, 2010 12:11 pm    Post subject: Reply with quote

1) You can include rvsoDefault0Style in the Options parameter.
With this option, properties of TextStyles[0], including font size and name, will not be written in HTML. For other text styles, their properties will be written in HTML only if they are different from properties of TextStyles[0].

2) It's arguable. In this way, the output does not depend on the browser settings (links are not necessary blue and underlined by default) and looks like in the editor.
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    trichview.com Forum Index -> Support All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group