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

📄 styleun.pas

📁 查看html文件的控件
💻 PAS
📖 第 1 页 / 共 5 页
字号:
  BorderStyle:
    begin
    Props[BorderStyle] := PropValue;
    Props[BorderTopStyle] := PropValue;
    Props[BorderRightStyle] := PropValue;
    Props[BorderBottomStyle] := PropValue;
    Props[BorderLeftStyle] := PropValue;
    end;
  else
    Props[Index] := PropValue;   
  end;
end;

procedure TProperties.AddPropertyByName(const PropName, PropValue: string);
var
  Index: PropIndices;
begin
if FindPropIndex(PropName, Index) then
  AddPropertyByIndex(Index, PropValue);
end;

constructor TStyleList.Create(AMasterList: TObject);
begin
inherited Create;
MasterList := AMasterList;
Sorted := True;
Duplicates := dupAccept;
SeqNo := 10;
end;

destructor TStyleList.Destroy;
begin
Clear;
inherited Destroy;
end;

procedure TStyleList.Clear;
var
  I: integer;
begin
for I := 0 to Count-1 do
  TProperties(Objects[I]).Free;
SeqNo := 10;
inherited;
end;

function TStyleList.GetSeqNo: string;
begin   {used to help sort contextual items by entry sequence}
Result := IntToStr(SeqNo);
Inc(SeqNo);
end;

{----------------TStyleList.AddModifyProp}
procedure TStyleList.AddModifyProp(const Selector, Prop, Value: string);
{strings are all lowercase here}
var
  I: integer;
  PropIndex: PropIndices;
  Propty: TProperties;
  NewColor: TColor;
  NewProp: boolean;
begin
if FindPropIndex(Prop, PropIndex) then
  begin
  if not Find(Selector, I) then
    begin
    NewProp := True;
    Propty := TProperties.Create  {newly created property}
    end
  else
    begin
    Propty := TProperties(Objects[I]); {modify existing property}
    NewProp := False;
    end;
  case PropIndex of
    Color:
      if ColorFromString(Value, False, NewColor) then
        begin
        if Selector = ':link' then
          begin      {changed the defaults to be the same as link}
          ModifyLinkColor('hover', NewColor);
          ModifyLinkColor('visited', NewColor);
          end
        else if Selector = ':visited' then
          ModifyLinkColor('hover', NewColor);
        Propty.Props[PropIndex] := NewColor;
        end;
    BorderColor:   
      if ColorFromString(Value, False, NewColor) then
        begin
        Propty.Props[BorderColor] := NewColor;
        Propty.Props[BorderLeftColor] := NewColor;
        Propty.Props[BorderTopColor] := NewColor;
        Propty.Props[BorderRightColor] := NewColor;
        Propty.Props[BorderBottomColor] := NewColor;
        end;
    BorderTopColor .. BorderLeftColor:     
      if ColorFromString(Value, False, NewColor) then
        Propty.Props[PropIndex] := NewColor;
    BackgroundColor:
      if ColorFromString(Value, False, NewColor) then
        Propty.Props[PropIndex] := NewColor
      else Propty.Props[PropIndex] := clNone;
    Visibility:
      begin
      if Value = 'visible' then
        Propty.Props[Visibility] := viVisible
      else if Value = 'hidden' then
        Propty.Props[Visibility] := viHidden;
      end;
    TextTransform:
      begin
      if Value = 'uppercase' then
        Propty.Props[TextTransform] := txUpper
      else if Value = 'lowercase' then
        Propty.Props[TextTransform] := txLower
      else Propty.Props[TextTransform] := txNone;
      end;
    WordWrap:    
      if Value = 'break-word' then
        Propty.Props[WordWrap] := Value
      else Propty.Props[WordWrap] := 'normal';
    FontVariant:
      if Value = 'small-caps' then
        Propty.Props[FontVariant] := Value
      else if Value = 'normal' then
        Propty.Props[FontVariant] := 'normal';
    BorderTopStyle..BorderLeftStyle:
      begin
      if Value <> 'none' then      
        Propty.Props[BorderStyle] := Value;
      Propty.Props[PropIndex] := Value;
      end;
    BorderStyle:
      begin
      Propty.Props[BorderStyle] := Value;
      Propty.Props[BorderTopStyle] := Value;
      Propty.Props[BorderRightStyle] := Value;
      Propty.Props[BorderBottomStyle] := Value;
      Propty.Props[BorderLeftStyle] := Value;
      end;
    LineHeight:
      Propty.Props[PropIndex] := Value;
    else
      Propty.Props[PropIndex] := Value;
    end;
  if NewProp then
    AddObject(Selector, Propty); {it's a newly created property}
  if Pos(':hover', Selector) > 0 then
    TSectionList(MasterList).LinksActive := True;
  if Selector = 'a' then
    begin
    AddModifyProp('::link', Prop, Value);  {also applies to ::link}
    end;
  {$ifdef Quirk}
  if (Selector = 'body') and (PropIndex = Color) then
    FixupTableColor(Propty);      
  {$endif}
  end;
end;

{$ifdef Quirk}
procedure TStyleList.FixupTableColor(BodyProp: TProperties);    
{if Quirk is set, make sure that the table color is defined the same as the
 body color}
var
  Propty1: TProperties;
  I: integer;
begin
if Find('td', I) then
  begin
  Propty1 := TProperties(Objects[I]);
  Propty1.Props[Color] := BodyProp.Props[Color];
  end;
if Find('th', I) then
  begin
  Propty1 := TProperties(Objects[I]);
  Propty1.Props[Color] := BodyProp.Props[Color];
  end;
end;
{$endif}

function TStyleList.AddObject(const S: string; AObject: TObject): Integer;
begin
Result := inherited AddObject(S, AObject);
TProperties(AObject).PropTag := S;
end;

function TStyleList.AddDuplicate(const Tag: string; Prop: TProperties): TProperties;
begin
Result := TProperties.Create;
Result.Copy(Prop);
AddObject(Tag, Result);
end;

procedure TStyleList.ModifyLinkColor(Psuedo: string; AColor: TColor);
var
  I: integer;
begin
if Find('::'+Psuedo, I) then   {the defaults}
  with TProperties(Objects[I]) do
      Props[Color] := AColor;
end;

procedure TStyleList.Initialize(const FontName, PreFontName: string;
     PointSize: integer; AColor, AHotspot, AVisitedColor, AActiveColor: TColor;
     LinkUnderline: boolean; ACharSet: TFontCharSet; MarginHeight, MarginWidth: integer);
type
  ListTypes = (ul, ol, menu, dir, dl, dd, blockquote);
const
  ListStr: array[Low(ListTypes)..High(ListTypes)] of string =
    ('ul', 'ol', 'menu', 'dir', 'dl', 'dd', 'blockquote'); 
var
  HIndex: integer;
  Properties: TProperties;
  J: ListTypes;
  F: double;

begin
Clear;
DefPointSize := PointSize;

Properties := TProperties.Create;
with Properties do
  begin
  DefFontname := FontName;    
  Props[FontFamily] := FontName;
  Props[FontSize] := PointSize*1.0;
  Props[FontStyle] := 'none';
  Props[FontWeight] := 'normal';
  Props[TextAlign] := 'left';
  Props[TextDecoration] := 'none';
  Props[TextTransform] := txNone;
  Props[WordWrap] := 'normal';
  Props[FontVariant] := 'normal';
  Props[Color] := AColor;
  Props[MarginTop] := MarginHeight;
  Props[MarginBottom] := MarginHeight;
  Props[MarginLeft] := MarginWidth;
  Props[MarginRight] := MarginWidth;
  Props[Visibility] := viVisible;
  Props[LetterSpacing] := 0;   
  CharSet := ACharSet;
  end;
AddObject('default', Properties);
DefProp := Properties;

{$ifdef Quirk}
Properties := TProperties.Create;   
with Properties do
  begin
  Props[FontSize] := PointSize*1.0;
  Props[FontStyle] := 'none';
  Props[FontWeight] := 'normal';
  Props[Color] := AColor;
  end;
AddObject('td', Properties);
Properties := AddDuplicate('th', Properties);  
  Properties.Props[FontWeight] := 'bold';
{$endif}

Properties := TProperties.Create;
with Properties do
  begin
  Props[Color] := AHotSpot or $2000000;
  if LinkUnderline then
    Props[TextDecoration] := 'underline'
  else
    Props[TextDecoration] := 'none';
  end;
AddObject('::link', Properties);    

Properties := TProperties.Create;
with Properties do
  Props[Color] := AVisitedColor or $2000000;
AddObject('::visited', Properties);    

Properties := TProperties.Create;
with Properties do
  Props[Color] := AActiveColor or $2000000;
AddObject('::hover', Properties);    

Properties := TProperties.Create;
AddObject('null', Properties);

Properties := TProperties.Create;
with Properties do
  begin
  Props[FontFamily] := PreFontName;
  Props[FontSize] := PointSize*10.0 / 12.0;
  Props[FontStyle] := 'none';
  Props[FontWeight] := 'normal';
  Props[TextDecoration] := 'none';
  end;
AddObject('pre', Properties);

Properties := TProperties.Create;
with Properties do
  begin
  Props[MarginTop] := AutoParagraph;
  Props[MarginBottom] := AutoParagraph;  
  end;
AddObject('p', Properties);

Properties := TProperties.Create;
with Properties do
  begin
  Props[MarginTop] := 0;
  end;
AddObject('p 11pre', Properties);

for J := Low(ListTypes) to High(ListTypes) do
  begin
  Properties := TProperties.Create;
  with Properties do
    begin
    Props[MarginLeft] := 35;
    Props[MarginTop] := 0;
    Props[MarginBottom] := 0;  
    case J of
      ol, ul, menu, dir:
          begin
          Props[ListStyleType] := 'blank';
          Props[MarginTop] := AutoParagraph;
          Props[MarginBottom] := AutoParagraph;
          end;
      dl: begin
          Props[MarginLeft] := 0;
          Props[ListStyleType] := 'none';
          end;
      blockquote:
          begin
          Props[MarginTop] := AutoParagraph;
          Props[MarginBottom] := ParagraphSpace;
          end;

      dd: begin
          Props[MarginLeft] := 40;
          end;
      end;
    end;
  AddObject(ListStr[J], Properties);
  end;

Properties := TProperties.Create;
with Properties do
  begin
  Props[FontFamily] := PrefontName;
  Props[FontSize] := '0.833em';  {10.0 / 12.0;} 
  end;
AddObject('code', Properties);
AddDuplicate('tt', Properties);
AddDuplicate('kbd', Properties);
AddDuplicate('samp', Properties);

Properties := TProperties.Create;
with Properties do
  begin
  Props[FontWeight] := 'bold';
  end;
AddObject('b', Properties);
AddDuplicate('strong', Properties);
{$ifndef Quirk}
AddDuplicate('th', Properties);     
{$endif}

Properties := TProperties.Create;
with Properties do
  begin
  Props[FontSize] := '75%';
  Props[VerticalAlign] := 'super';
  end;
AddObject('sup', Properties);

Properties := TProperties.Create;
with Properties do
  begin
  Props[FontSize] := '75%';
  Props[VerticalAlign] := 'sub';
  end;
AddObject('sub', Properties);

Properties := TProperties.Create;
with Properties do
  begin
  Props[FontSize] := '1.25em';
  end;
AddObject('big', Properties);

Properties := TProperties.Create;
with Properties do
  begin
  Props[FontSize] := '0.75em';
  end;
AddObject('small', Properties);

Properties := TProperties.Create;
with Properties do
  begin
  Props[TextAlign] := 'none';    
  end;
AddObject('table', Properties);

Properties := TProperties.Create;
with Properties do
  begin
  Props[FontStyle] := 'italic';
  end;
AddObject('i', Properties);
AddDuplicate('em', Properties);
AddDuplicate('cite', Properties);
AddDuplicate('var', Properties);

AddDuplicate('address', Properties);

Properties := TProperties.Create;
with Properties do
  begin
  Props[TextDecoration] := 'underline';
  end;
AddObject('u', Properties);

Properties := TProperties.Create;
with Properties do
  begin
  Props[TextDecoration] := 'line-through';
  end;
AddObject('s', Properties);
AddDuplicate('strike', Properties);

Properties := TProperties.Create;
with Properties do
  begin
  Props[TextAlign] := 'center';
  end;
AddObject('center', Properties);
AddDuplicate('caption', Prop

⌨️ 快捷键说明

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