diff --git a/components/richmemo/gtk2/gtk2richmemo.pas b/components/richmemo/gtk2/gtk2richmemo.pas index 97137af4a..1ad482c04 100644 --- a/components/richmemo/gtk2/gtk2richmemo.pas +++ b/components/richmemo/gtk2/gtk2richmemo.pas @@ -45,10 +45,56 @@ type published class function CreateHandle(const AWinControl: TWinControl; const AParams: TCreateParams): TLCLIntfHandle; override; class procedure SetTextAttributes(const AWinControl: TWinControl; TextStart, TextLen: Integer; const Params: TIntFontParams); override; + class function GetTextAttributes(const AWinControl: TWinControl; TextStart: Integer; var Params: TIntFontParams): Boolean; override; end; implementation + +function gtktextattr_underline(const a : TGtkTextAppearance) : Boolean; +begin + Result:=((a.flag0 and bm_TGtkTextAppearance_underline) shr bp_TGtkTextAppearance_underline) > 0; +end; + +function gtktextattr_strikethrough(const a : TGtkTextAppearance) : Boolean; +begin + Result:=((a.flag0 and bm_TGtkTextAppearance_strikethrough) shr bp_TGtkTextAppearance_strikethrough) > 0; +end; + +function GtkTextAttrToFontParams(const textAttr: TGtkTextAttributes; var FontParams: TIntFontParams): Boolean; +var + w : integer; + st : TPangoStyle; + pf : PPangoFontDescription; +begin + FontParams.Style := []; + FontParams.Name := ''; + FontParams.Size := 0; + FontParams.Color := 0; + + pf := textAttr.font; + Result := Assigned(pf); + if not Result then Exit; + + if Assigned(pf) then begin + FontParams.Name := pango_font_description_get_family(pf); + FontParams.Size := pango_font_description_get_size(pf); + if not pango_font_description_get_size_is_absolute(pf) then + FontParams.Size := Round(FontParams.Size / PANGO_SCALE); + + w := pango_font_description_get_weight(pf); + if w > PANGO_WEIGHT_NORMAL then Include(FontParams.Style, fsBold); + + st := pango_font_description_get_style(pf); + if st and PANGO_STYLE_ITALIC > 0 then Include(FontParams.Style, fsItalic); + end; + + FontParams.Color := TGDKColorToTColor(textAttr.appearance.fg_color); + if gtktextattr_underline(textAttr.appearance) then Include(FontParams.Style, fsUnderline); + if gtktextattr_strikethrough(textAttr.appearance) then Include(FontParams.Style, fsStrikeOut); +end; + + class procedure TGtk2WSCustomRichMemo.SetCallbacks( const AGtkWidget: PGtkWidget; const AWidgetInfo: PWidgetInfo); begin @@ -135,19 +181,19 @@ begin if nm = '' then nm := #0; tag := gtk_text_buffer_create_tag (buffer, nil, - 'foreground-gdk', [@gcolor, - 'size-set', gboolean(true), - 'size-points', Double(Params.Size), - 'underline-set', gboolean(True), - 'underline', PangoUnderline[fsUnderline in Params.Style], - 'weight-set', gboolean(True), - 'weight', PangoBold[fsBold in Params.Style], - 'style-set', gboolean(True), - 'style', PangoItalic[fsItalic in Params.Style], - 'strikethrough-set', gboolean(True), - 'strikethrough ', gboolean(fsStrikeOut in Params.Style), - 'familty-set', gboolean(true), + 'family-set', [gboolean(gTRUE), 'family', @nm[1], + 'foreground-gdk', @gcolor, + 'size-set', gboolean(gTRUE), + 'size-points', Double(Params.Size), + 'underline-set', gboolean(gTRUE), + 'underline', PangoUnderline[fsUnderline in Params.Style], + 'weight-set', gboolean(gTRUE), + 'weight', PangoBold[fsBold in Params.Style], + 'style-set', gboolean(gTRUE), + 'style', PangoItalic[fsItalic in Params.Style], + 'strikethrough-set', gboolean(gTRUE), + 'strikethrough', gboolean(fsStrikeOut in Params.Style), nil]); gtk_text_buffer_get_iter_at_offset (buffer, @istart, TextStart); @@ -155,5 +201,39 @@ begin gtk_text_buffer_apply_tag(buffer, tag, @istart, @iend); end; + +class function TGtk2WSCustomRichMemo.GetTextAttributes(const AWinControl: TWinControl; TextStart: Integer; var Params: TIntFontParams): Boolean; +var + Widget : PGtkWidget; + TextWidget : PGtkWidget; + list : PGList; + buffer : PGtkTextBuffer; + iter : TGtkTextIter; + attr : PGtkTextAttributes; +begin + Widget := PGtkWidget(PtrUInt(AWinControl.Handle)); + + list := gtk_container_get_children(PGtkContainer(Widget)); + if not Assigned(list) then Exit; + + TextWidget := PGtkWidget(list^.data); + if not Assigned(TextWidget) then Exit; + + buffer := gtk_text_view_get_buffer (PGtkTextView(TextWidget)); + if not Assigned(buffer) then Exit; + + attr := gtk_text_view_get_default_attributes(PGtkTextView(TextWidget)); + Result := Assigned(attr); + if not Assigned(attr) then Exit; + + gtk_text_buffer_get_iter_at_offset(buffer, @iter, TextStart); + Result := gtk_text_iter_get_attributes(@iter, attr); + //if Result then + {Result := } + Result := true; + GtkTextAttrToFontParams(attr^, Params); + gtk_text_attributes_unref(attr); +end; + end.