Recent

Author Topic: Bounty $60: rework of GTK2 ExtTextOut to use new API  (Read 1132 times)

AlexTP

  • Hero Member
  • *****
  • Posts: 2457
    • UVviewsoft
Bounty $60: rework of GTK2 ExtTextOut to use new API
« on: June 16, 2024, 08:21:07 pm »
I want to suggest such small bounty.
It should affect speed of text rendering in my text editor CudaText.
If it will not affect the speed, it will be problematic patch, which I dislike and cannot give the bounty.

Current ExtTextOut in GTK2 calls this core function
(file lcl/interfaces/gtk2/gtk2devicecontext.inc)
Code: Pascal  [Select][+][-]
  1. procedure TGtkDeviceContext.DrawTextWithColors(AText: PChar; ALength: LongInt;
  2.   X, Y: Integer; FGColor, BGColor: PGdkColor);
  3. var
  4.   WidgetCont: PPangoContext;
  5.   NewMatrix: TPangoMatrix;
  6.   OldMatrix: PPangoMatrix;
  7.   renderer: PGdkPangoRenderer;
  8.   Direction : TPangoDirection;
  9.   AFont: PGdiObject;
  10.  
  11.   procedure SetColors(AFGColor, ABGColor: PGdkColor); inline;
  12.   begin
  13.     gdk_pango_renderer_set_override_color(renderer, PANGO_RENDER_PART_FOREGROUND, AFGColor);
  14.     gdk_pango_renderer_set_override_color(renderer, PANGO_RENDER_PART_UNDERLINE, AFGColor);
  15.     gdk_pango_renderer_set_override_color(renderer, PANGO_RENDER_PART_STRIKETHROUGH, AFGColor);
  16.     gdk_pango_renderer_set_override_color(renderer, PANGO_RENDER_PART_BACKGROUND, ABGColor);
  17.   end;
  18.  
  19. begin
  20.   AFont := GetFont;
  21.   SetLayoutText(AFont^.GDIFontObject, AText, ALength);
  22.  
  23.   WidgetCont := pango_layout_get_context(AFont^.GDIFontObject);
  24.   Direction := pango_find_base_dir(AText, ALength);
  25.   pango_context_set_base_dir(WidgetCont, Direction);
  26.  
  27.   if AFont^.LogFont.lfEscapement <> 0 then
  28.   begin
  29.     if Widget <> nil then
  30.       renderer := gdk_pango_renderer_get_default(gtk_widget_get_screen(Widget))
  31.     else
  32.       renderer := gdk_pango_renderer_get_default(gdk_screen_get_default);
  33.     RemovePixbuf;
  34.     gdk_pango_renderer_set_drawable(renderer, drawable);
  35.     gdk_pango_renderer_set_gc(renderer, GC);
  36.     SetColors(FGColor, BGColor);
  37.  
  38.     OldMatrix := pango_context_get_matrix(WidgetCont);
  39.     NewMatrix.xx := 1.0;
  40.     NewMatrix.xy := 0.0;
  41.     NewMatrix.yx := 0.0;
  42.     NewMatrix.yy := 1.0;
  43.     NewMatrix.x0 := 0.0;
  44.     NewMatrix.y0 := 0.0;
  45.     pango_matrix_translate(@NewMatrix, X, Y);
  46.     pango_matrix_rotate(@NewMatrix, AFont^.LogFont.lfEscapement / 10);
  47.  
  48.     pango_context_set_matrix(WidgetCont, @NewMatrix);
  49.     pango_layout_context_changed(AFont^.GDIFontObject);
  50.     pango_renderer_draw_layout(PPangoRenderer(renderer), AFont^.GDIFontObject, X, Y);
  51.  
  52.     //now reset
  53.     pango_context_set_matrix(WidgetCont, OldMatrix);
  54.     pango_layout_context_changed(AFont^.GDIFontObject);
  55.    
  56.     SetColors(nil, nil);
  57.     gdk_pango_renderer_set_drawable(renderer, nil);
  58.     gdk_pango_renderer_set_gc(renderer, nil);
  59.   end
  60.   else
  61.     gdk_draw_layout_with_colors(drawable, GC, X, Y, AFont^.GDIFontObject, FGColor, BGColor);
  62. end;
  63.  

I looked at the GTK2 docs about these gdk_xxxxx APIs and docs say that they are deprecated! We must use some newer API from GTK2.
I don't have URL at hands, so please look at docs by yourself. If you won't find this text, I will help to find it.
« Last Edit: June 16, 2024, 08:24:25 pm by AlexTP »

 

TinyPortal © 2005-2018