Ignore:
Timestamp:
Jun 22, 2010, 8:22:30 AM (14 years ago)
Author:
Kevin Toppenberg
Message:

Corrected HTML line feed

File:
1 edited

Legend:

Unmodified
Added
Removed
  • cprs/branches/tmg-cprs/CPRS-Chart/rHTMLTools.pas

    r793 r809  
    1818    URL_CPRSDir : string;  //This is CPRSDir, but all '\'s are converted to '/'s
    1919
    20   CONST ALT_IMG_TAG_CONVERT = 'alt="convert to $CPRSDIR$"';
     20  CONST
     21    CPRS_DIR_SIGNAL = '$CPRSDIR$';
     22    CPRS_CACHE_DIR_SIGNAL = CPRS_DIR_SIGNAL+'\Cache\';
     23    ALT_IMG_TAG_CONVERT = 'alt="convert to ' + CPRS_DIR_SIGNAL +'"';
    2124
    2225  procedure PrintHTMLReport(Lines: TStringList; var ErrMsg: string;
     
    4346  Procedure ScanForSubs(Lines : TStrings);
    4447  Procedure InsertSubs(Lines : TStrings);
     48  function HTTPEncode(const AStr: string): string;
    4549
    4650implementation
     
    217221    SubsFoundList.Clear;
    218222    for i := 0 to Lines.Count-1 do begin
    219       p := Pos('$CPRSDIR$',Lines.Strings[i]);
     223      p := Pos(CPRS_DIR_SIGNAL,Lines.Strings[i]);
    220224      if p>0 then begin
    221         p := p + Length('$CPRSDIR$\Cache\');
     225        p := p + Length(CPRS_CACHE_DIR_SIGNAL);
    222226        p2 := PosEx('"',Lines.Strings[i],p);
    223227        tempS := MidStr(Lines.Strings[i],p,(p2-p));
    224228        SubsFoundList.Add(tempS);
    225229        if Pos('file:///',Lines.Strings[i]) > 0 then begin
    226           Lines.Strings[i] := AnsiReplaceStr(Lines.Strings[i],'$CPRSDIR$',URL_CPRSDir);
     230          Lines.Strings[i] := AnsiReplaceStr(Lines.Strings[i],CPRS_DIR_SIGNAL,URL_CPRSDir);
    227231        end else begin
    228           Lines.Strings[i] := AnsiReplaceStr(Lines.Strings[i],'$CPRSDIR$',CPRSDir);
     232          Lines.Strings[i] := AnsiReplaceStr(Lines.Strings[i],CPRS_DIR_SIGNAL,CPRSDir);
    229233        end;
    230234        //Ensure images are downloaded before passing page to web browser
     
    237241  Procedure InsertSubs(Lines : TStrings);
    238242  //Purpose: To scan a edited note images, and replace references to CPRS's
    239   //         actual local directory with $CPRS$
     243  //         actual local directory with CPRS_DIR_SIGNAL ('$CPRSDIR$')
    240244  var i,p : integer;
    241245     TempS: string;
     
    243247  begin
    244248    for i := 0 to Lines.Count-1 do begin
    245       Lines.Strings[i] := AnsiReplaceStr(Lines.Strings[i],URL_CPRSDir,'$CPRSDIR$');
     249      p := pos(ALT_IMG_TAG_CONVERT,Lines.Strings[i]);
     250      if p = 0 then continue;
     251      TempS := Lines.Strings[i];
     252      Lines.Strings[i] := AnsiReplaceStr(Lines.Strings[i],URL_CPRSDir,CPRS_DIR_SIGNAL);
     253      if Lines.Strings[i] = TempS then begin  //There is a problem. Replacement failed.
     254        MessageDlg('Problem converting image path to $CPRSDIR$',mtWarning,[mbOK],0);
     255      end;
     256      //TempS := MidStr(Lines.Strings[i],1,p-1);
     257      //TempS := TempS + MidStr(Lines.Strings[i],p+length(ALT_IMG_TAG_CONVERT),length(Lines.Strings[i])+1);
     258      //Lines.Strings[i] := TempS;
    246259      Lines.Strings[i] := AnsiReplaceStr(Lines.Strings[i],ALT_IMG_TAG_CONVERT,'IMAGE'); //Remove signal
    247       p := pos(ALT_IMG_TAG_CONVERT,Lines.Strings[i]);
    248       if p > 0 then begin
    249         TempS := MidStr(Lines.Strings[i],1,p-1);
    250         TempS := TempS + MidStr(Lines.Strings[i],p+length(ALT_IMG_TAG_CONVERT),length(Lines.Strings[i])+1);
    251         Lines.Strings[i] := TempS;
    252       end;
    253260    end;
    254261  end;
     
    504511    Result := AnsiReplaceText(Result,'>'+CRLF,'>'#$1F); //protect sequences we want
    505512    Result := AnsiReplaceText(Result,CRLF,'<BR>'+CRLF); //Add <BR>'s to CrLf's
    506     Result := AnsiReplaceText(Result,'>'#$1F,'>'+CRLF); //Restore sequences we wanted
     513    Result := AnsiReplaceText(Result,'>'#$1F,'><BR>'+CRLF); //Restore sequences we wanted
    507514    Result := AnsiReplaceText(Result,#$1E,'<NO DATA>'); //Restore sequences we wanted
    508515  end;
     
    829836  //elh 6/19/09
    830837  begin
    831     if not assigned(Reg) then Reg := TRegistry.Create;
     838    if not assigned(Reg) then begin
     839       Reg := TRegistry.Create;
     840       Reg.Rootkey := HKEY_CURRENT_USER;
     841       Reg.OpenKey('\Software\Microsoft\Internet Explorer\PageSetup', False)
     842    end;   
    832843    try
    833844      StoredIEFooters := '&u&b&d';          //Comment this line to restore previous value
     
    853864      s := Piece(Lines.Strings[i],'DATE OF NOTE:',2);
    854865      s := Piece(s,'@',1);
    855       Result := Trim(s);     
    856     end;
    857   end;
     866      Result := Trim(s);
     867    end;
     868  end;
     869
     870  function HTTPEncode(const AStr: string): string;
     871  //NOTE: routine from here:
     872  //   http://www.delphitricks.com/source-code/internet/encode_a_http_url.html
     873  //NOTE: I modified this to my purposes.  I removed conversion of '/',':'
     874  const
     875    //kt original --> NoConversion = ['A'..'Z', 'a'..'z', '*', '@', '.', '_', '-'];
     876    NoConversion = ['A'..'Z', 'a'..'z', '*', '@', '.', '_', '-', '/', ':'];  //kt
     877  var
     878    Sp, Rp: PChar;
     879  begin
     880    SetLength(Result, Length(AStr) * 3);
     881    Sp := PChar(AStr);
     882    Rp := PChar(Result);
     883    while Sp^ <> #0 do begin
     884      if Sp^ in NoConversion then
     885        Rp^ := Sp^
     886      //kt else if Sp^ = ' ' then
     887      //kt   Rp^ := '+'
     888      else begin
     889        FormatBuf(Rp^, 3, '%%%.2x', 6, [Ord(Sp^)]);
     890        Inc(Rp, 2);
     891      end;
     892      Inc(Rp);
     893      Inc(Sp);
     894    end;
     895    SetLength(Result, Rp - PChar(Result));
     896  end;
     897
    858898
    859899  //===============================================================
     
    883923    RestorePrinterTimer.Enabled := false;
    884924    RestoreIEPrinting;   {elh 6/19/09}  //kt
    885     //kt SetDefaultPrinter(SavedDefaultPrinter);   
     925    //kt SetDefaultPrinter(SavedDefaultPrinter);
    886926    //beep;   
    887   end; 
     927  end;
    888928
    889929  //===============================================================
    890  
     930
     931  function EncodePath(var Path : string) : string;
     932  begin
     933    Result := AnsiReplaceStr(Path,'\','/');
     934    Result := HTTPEncode(Result);
     935  end;
    891936
    892937initialization
     
    894939  PrinterEvents := TPrinterEvents.Create;
    895940  CPRSDir := ExcludeTrailingPathDelimiter(ExtractFilePath(ParamStr(0)));
    896   URL_CPRSDir := AnsiReplaceStr(CPRSDir,'\','/');
     941  URL_CPRSDir := EncodePath(CPRSDir);
    897942  SubsFoundList := TStringList.Create;
    898943
    899944finalization
     945  //kt causing crash -->  Reg.WriteString('footer',StoredIEFooters);
     946  //RestoreIEPrinting;
    900947  PrinterEvents.Free;
    901948  SubsFoundList.Free;
Note: See TracChangeset for help on using the changeset viewer.