⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 rvrtfprops.pas

📁 richview1.7 full.source
💻 PAS
📖 第 1 页 / 共 5 页
字号:
    exit;
  if LastMarkerIndex>=0 then begin
    Marker := CurrentRVData.GetItem(LastMarkerIndex) as TRVMarkerItemInfo;
    Marker.ListNo := GetMarkerIndex(Reader.RTFState.ParaProps.MarkerProps);
    if Marker.ListNo>=0 then begin
      Marker.Level := 0;
      {
      CurrentRVData.State := CurrentRVData.State+[rvstMarkersBadlyNeeded];
      try
      }
        CurrentRVData.RecalcMarker(LastMarkerIndex, True);
      {
      finally
        CurrentRVData.State := CurrentRVData.State-[rvstMarkersBadlyNeeded];
      end;
      }
    end;
    LastMarkerIndex := -1;
  end;
end;
{------------------------------------------------------------------------------}
procedure ConvMarker97(Reader: TRVRTFReader;
                     RTFMarker: TRVRTFListLevel97;
                     var RVType: TRVListType;
                     var FormatStr1,FormatStr2: String;
                     var FormatStrW:
                     {$IFDEF RICHVIEWCBDEF3}WideString{$ELSE}String{$ENDIF}
                     );
var i: Integer;
    s1,s2: String;
    FontName: String;
begin
  case RTFMarker.ListType of
    rtf_pn_Decimal:
      RVType := rvlstDecimal;
    rtf_pn_LowerLetter:
      RVType := rvlstLowerAlpha;
    rtf_pn_UpperLetter:
      RVType := rvlstUpperAlpha;
    rtf_pn_LowerRoman:
      RVType := rvlstLowerRoman;
    rtf_pn_UpperRoman:
      RVType := rvlstUpperRoman;
    rtf_pn_Bullet:
      RVType := rvlstBullet;
  end;
  FormatStr1 := Copy(RTFMarker.Text, 2, Length(RTFMarker.Text)-1);
  FormatStr2 := FormatStr1;
  for i := Length(FormatStr1) downto 1 do
    if FormatStr1[i] in [#0..#9] then begin
      s2 := '%'+IntToStr(ord(FormatStr1[i]))+':s';
      if FormatStr1[i]=#0 then
        s1 := '%s'
      else
        s1 := s2;
      Delete(FormatStr1,i,1);
      Insert(s1, FormatStr1, i);
      Delete(FormatStr2,i,1);
      Insert(s2, FormatStr2, i);
    end;
  FormatStrW := '';
  {$IFNDEF RVDONOTUSEUNICODE}
  if (RTFMarker.TextW<>'') and (RTFMarker.ListType=rtf_pn_Bullet) then begin
    RVType := rvlstUnicodeBullet;
    FormatStrW := Copy(RTFMarker.TextW, 2, Length(RTFMarker.TextW)-1);
    if (Length(FormatStrW)=1) then begin
      FontName := Reader.FontTable[RTFMarker.FontIndex].Name;
      if (Word(FormatStrW[1])>=61601) and (Word(FormatStrW[1])<=61694) and
         (CompareText(FontName, 'Symbol')=0) then begin
        FormatStr1 := chr(Word(FormatStrW[1])-61601+161);
        FormatStr2 := FormatStr1;
        RVType := rvlstBullet;
      end;
      if (Word(FormatStrW[1])>=61473) and (Word(FormatStrW[1])<=61695) and
         (CompareText(FontName, 'Wingdings')=0) then begin
        FormatStr1 := chr(Word(FormatStrW[1])-61473+33);
        FormatStr2 := FormatStr1;
        RVType := rvlstBullet;
      end;
    end;
  end;
  {$ENDIF}
end;
{------------------------------------------------------------------------------}
function AreLevelsEqual97(RVLevel: TRVListLevel; RTFLevel: TRVRTFListLevel97;
                     RVType: TRVListType;
                     const FontName, FormatStr1, FormatStr2: String;
                     const FormatStrW: {$IFDEF RICHVIEWCBDEF3}WideString{$ELSE}String{$ENDIF};
                     PixelsPerTwip: Double): Boolean;
begin
  Result :=  (RVLevel.ListType = RVType) and
            (RVLevel.StartFrom = RTFLevel.Start) and
            (RVLevel.MarkerAlignment = TRVMarkerAlignment(RTFLevel.Alignment)) and
            (RVLevel.LeftIndent = Round(RTFLevel.LeftIndentTw*PixelsPerTwip)) and
            (RVLevel.MarkerIndent = Round(RTFLevel.FirstIndentTw*PixelsPerTwip)+RVLevel.LeftIndent) and
            (RVLevel.FirstIndent = Round(RTFLevel.TabPosTw*PixelsPerTwip)-RVLevel.LeftIndent) and
            (RTFLevel.NoRestart = not (rvloLevelReset in RVLevel.Options)) and
            (RTFLevel.Legal = (rvloLegalStyleNumbering in RVLevel.Options)) and
            (RVLevel.Font.Style = RTFLevel.FontStyle) and
            (RVLevel.Font.Color = RTFLevel.Color) and
            (RVLevel.Font.Size  = RTFLevel.FontSize) and
            (CompareText(RVLevel.Font.Name, FontName) = 0);
  if not Result then
    exit;
  case RVType of
    rvlstDecimal,rvlstLowerAlpha,
    rvlstUpperAlpha,rvlstLowerRoman,
    rvlstUpperRoman,rvlstBullet:
      Result := (RVLevel.FormatString=FormatStr1) or
                (RVLevel.FormatString=FormatStr2);
    {$IFNDEF RVDONOTUSEUNICODE}
    rvlstUnicodeBullet:
      Result := (RVLevel.FormatStringW=FormatStrW);
    {$ENDIF}
  end;
end;
{------------------------------------------------------------------------------}
function TRVRTFReaderProperties.AreListStylesEqual97(RVList: TRVListInfo; RTFList: TRVRTFList97): Boolean;
var
  RVType: TRVListType;
  FontName, FormatStr1, FormatStr2: String;
  FormatStrW: {$IFDEF RICHVIEWCBDEF3}WideString{$ELSE}String{$ENDIF};
  RTFLevel: TRVRTFListLevel97;
  i: Integer;
begin
  Result := RVList.Levels.Count>=RTFList.Count;
  if not Result then
    exit;
  for i := 0 to RTFList.Count-1 do begin
     RTFLevel := RTFList.Items[i];
      ConvMarker97(Reader, RTFLevel, RVType, FormatStr1, FormatStr2, FormatStrW);
      FontName := Reader.FontTable[RTFLevel.FontIndex].Name;
      Result := AreLevelsEqual97(RVList.Levels[i], RTFLevel, RVType,
        FontName,FormatStr1,FormatStr2,FormatStrW,PixelsPerTwip);
      if not Result then
        exit;
  end;
end;
{------------------------------------------------------------------------------}
function TRVRTFReaderProperties.FindListStyle97(RTFList: TRVRTFList97;
  ForbiddenStyles: TRVIntegerList): Integer;
var i: Integer;
begin
  if ParaStyleMode=rvrsAddIfNeeded then
    for i := 0 to RVStyle.ListStyles.Count-1 do
      if (ForbiddenStyles.IndexOf(Pointer(i))<0) and
         AreListStylesEqual97(RVStyle.ListStyles[i], RTFList) then begin
        Result := i;
        exit;
      end;
  Result := -1;
end;
{------------------------------------------------------------------------------}
procedure TRVRTFReaderProperties.MergeListTable97;
var i,j: Integer;
    RVLevel : TRVListLevel;
    RTFLevel: TRVRTFListLevel97;
    FormatStr1,FormatStr2,FontName: String;
    FormatStrW: {$IFDEF RICHVIEWCBDEF3}WideString{$ELSE}String{$ENDIF};
    {$IFDEF RICHVIEWCBDEF3}
    Charset: TFontCharset;
    {$ENDIF}
    RVType: TRVListType;
    ListNo: Integer;
    ForbiddenStyles: TRVIntegerList;
begin
  if ParaStyleMode<>rvrsAddIfNeeded then
    exit;
  if ListTableMap97<>nil then
    exit;
  ForbiddenStyles := TRVIntegerList.Create;
  try
    ListTableMap97 := TRVIntegerList.Create;
    for i := 0 to Reader.ListTable.Count-1 do begin
      ListNo := FindListStyle97(Reader.ListTable[i], ForbiddenStyles);
      if ListNo>=0 then begin
        ListTableMap97.Add(ListNo);
        ForbiddenStyles.Add(ListNo);
        end
      else begin
        RVStyle.ListStyles.Add;
        RVStyle.ListStyles[RVStyle.ListStyles.Count-1].Standard := False;
        ListTableMap97.Add(RVStyle.ListStyles.Count-1);
        ForbiddenStyles.Add(RVStyle.ListStyles.Count-1);
        for j := 0 to Reader.ListTable[i].Count-1 do begin
          RTFLevel := Reader.ListTable[i].Items[j];
          ConvMarker97(Reader, RTFLevel, RVType, FormatStr1, FormatStr2, FormatStrW);
          FontName := Reader.FontTable[RTFLevel.FontIndex].Name;
          {$IFDEF RICHVIEWCBDEF3}
          Charset  := Reader.FontTable[RTFLevel.FontIndex].Charset;
          {$ENDIF}
          RVLevel := RVStyle.ListStyles[RVStyle.ListStyles.Count-1].Levels.Add;
          RVLevel.ListType := RVType;
          RVLevel.FormatString := FormatStr1;
          {$IFNDEF RVDONOTUSEUNICODE}
          RVLevel.FormatStringW := FormatStrW;
          {$ENDIF}
          RVLevel.MarkerAlignment := TRVMarkerAlignment(RTFLevel.Alignment);
          RVLevel.Font.Name := FontName;
          {$IFDEF RICHVIEWCBDEF3}
          RVLevel.Font.Charset  := Charset;
          {$ENDIF}
          RVLevel.Font.Style := RTFLevel.FontStyle;
          RVLevel.Font.Color := RTFLevel.Color;
          RVLevel.Font.Size  := RTFLevel.FontSize;
          RVLevel.LeftIndent := Round(RTFLevel.LeftIndentTw*PixelsPerTwip);
          RVLevel.MarkerIndent := Round(RTFLevel.FirstIndentTw*PixelsPerTwip)+RVLevel.LeftIndent;
          RVLevel.FirstIndent := Round(RTFLevel.TabPosTw*PixelsPerTwip)-RVLevel.LeftIndent;
          RVLevel.StartFrom   := RTFLevel.Start;
          if RTFLevel.NoRestart then
            RVLevel.Options := RVLevel.Options - [rvloLevelReset];
          if RTFLevel.Legal then
            RVLevel.Options := RVLevel.Options + [rvloLegalStyleNumbering];
        end;
      end;
    end;
  finally
    ForbiddenStyles.Free;
  end;
end;
{$ENDIF}
{------------------------------------------------------------------------------}
procedure TRVRTFReaderProperties.NewReaderText(Sender: TRVRTFReader;
  const Text: String; Position: TRVRTFPosition);
var StyleNo : Integer;
    item    : TRVTextItemInfo;
    s: String;
begin
  if FSkipHiddenText and Reader.RTFState.CharProps.Hidden then
    exit;
  StyleNo := ReturnStyleNo(UnicodeMode=rvruOnlyUnicode);
  item := CreateTextItem(Text,
                         {$IFDEF RICHVIEWCBDEF3} '', {$ENDIF}
                         StyleNo, ReturnParaNo(Position), False, s);
  InsertItem(s, item, Position);
end;
{------------------------------------------------------------------------------}
{$IFDEF RICHVIEWCBDEF3}
procedure TRVRTFReaderProperties.NewReaderUnicodeText(Sender: TRVRTFReader;
  const Text: WideString; Position: TRVRTFPosition);
var StyleNo : Integer;
    item    : TRVTextItemInfo;
    s: String;
begin
  if FSkipHiddenText and Reader.RTFState.CharProps.Hidden then
    exit;
  StyleNo := ReturnStyleNo(UnicodeMode in [rvruOnlyUnicode, rvruMixed]);
  item := CreateTextItem('', Text, StyleNo, ReturnParaNo(Position), True, s);
  InsertItem(s, item, Position);
end;
{$ENDIF}
{------------------------------------------------------------------------------}
procedure TRVRTFReaderProperties.ReaderHeaderFooter(Sender: TRVRTFReader; HFType: TRVRTFHeaderFooterType; Starting: Boolean);
begin
  // 1 twip = 20 points = 1/1440 inch
  if Starting then
    case HFType of
      rtf_hf_Header:
        if FHeaderRVData<>nil then begin
          CurrentRVData := FHeaderRVData;
          CurrentRVData.Clear;
          FHeaderYMM := Round(Reader.RTFState.SectProps.HeaderYTw*127/(1440*5));
        end;
      rtf_hf_Footer:
        if FFooterRVData<>nil then begin
          CurrentRVData := FFooterRVData;
          CurrentRVData.Clear;
          FFooterYMM := Round(Reader.RTFState.SectProps.FooterYTw*127/(1440*5));
        end;
    end
  else begin
    CurrentRVData := RVData;
  end;
  RVStyle := CurrentRVData.GetRVStyle;
  Self.HFType := HFType;
end;
{------------------------------------------------------------------------------}
procedure TRVRTFReaderProperties.ReaderPageBreak(Sender: TObject);
begin
  PageBreak := True;
end;
{------------------------------------------------------------------------------}
procedure TRVRTFReaderProperties.InitReader;
begin
  PixelsPerTwip := Screen.PixelsPerInch / (72*20);
  Reader.ConvertHighlight := TRVRTFHighlightConvert(ConvertHighlight);
  Reader.BasePath := BasePath;
  HFType := rtf_hf_MainText;
  {$IFNDEF RVDONOTUSELISTS}
  Reader.OnUpdateMarker := ReaderUpdateMarker;
  LastMarkerIndex := -1;
  LevelToListNo := TRVIntegerList.Create;
  {$ENDIF}
  Reader.OnNewText := NewReaderText;
  {$IFNDEF RVDONOTUSEUNICODE}
  if UnicodeMode in [rvruMixed, rvruOnlyUnicode] then
    Reader.OnNewUnicodeText := NewReaderUnicodeText;
  {$ENDIF}
  if not IgnorePictures then
    Reader.OnNewPicture := NewReaderPicture;
  Reader.DefCodePage := RVData.GetDefaultCodePage;
  Reader.OnRequiredPageBreak := ReaderPageBreak;
  {$IFNDEF RVDONOTUSETABLES}
  Reader.OnTable     := ReaderTable;
  {$ENDIF}
  RVStyle := RVData.GetRVStyle;
  PageBreak := False;
  NonFirstItemsAdded := 0;
  FirstTime := True;
  FailedBecauseOfProtect := False;
  FullReformat := False;
  Tables    := nil;
  CurrentRVData := RVData;
  CurrentRow := -1;
  CurrentCol := -1;
  FEmptyPara := -1;
  FHeaderYMM := -1;
  FFooterYMM := -1;
  if (FHeaderRVData<>nil) or (FFooterRVData<>nil) then
    Reader.OnHeaderFooter := ReaderHeaderFooter;
  if (FHeaderRVData<>nil) then
    FHeaderRVData.Clear;
  if (FFooterRVData<>nil) then
    FFooterRVData.Clear;
end;
{------------------------------------------------------------------------------}
procedure TRVRTFReaderProperties.DoneReader;
begin
  {$IFNDEF RVDONOTUSELISTS}
  ReaderUpdateMarker(nil);
  {$ENDIF}
  Tables.Free;
  Tables := nil;
  {$IFNDEF RVDONOTUSELISTS}
  LevelToListNo.Free;
  LevelToListNo := nil;
  ListTableMap97.Free;
  ListTableMap97 := nil;
  {$END

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -