Guest User

.text.lua

a guest
Aug 14th, 2014
339
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 20.64 KB | None | 0 0
  1. --[[TEXT WIDGET v1.. by Wlourf 25/06/2010
  2. This widget can drawn texts set in the "text_settings" table with some parameters
  3. http://u-scripts.blogspot.com/2010/06/text-widget.html
  4.  
  5. The parameters (all optionals) are :
  6. text        - text to display, default = "Conky is good for you"
  7.               use conky_parse to display conky value ie text=conly_parse("${cpu cpu1}")
  8.             - coordinates below are relative to top left corner of the conky window
  9. x           - x coordinate of first letter (bottom-left), default = center of conky window
  10. y           - y coordinate of first letter (bottom-left), default = center of conky window
  11. h_align     - horizontal alignement of text relative to point (x,y), default="l"
  12.               available values are "l": left, "c" : center, "r" : right
  13. v_align     - vertical alignment of text relative to point (x,y), default="b"
  14.               available values "t" : top, "m" : middle, "b" : bottom
  15. font_name   - name of font to use, default = Free Sans
  16. font_size   - size of font to use, default = 14
  17. italic      - display text in italic (true/false), default=false
  18. oblique     - display text in oblique (true/false), default=false (I don' see the difference with italic!)
  19. bold        - display text in bold (true/false), default=false
  20. angle       - rotation of text in degrees, default = 0 (horizontal)
  21. colour      - table of colours for text, default = plain white {{1,0xFFFFFF,1}}
  22.               this table contains one or more tables with format {P,C,A}
  23.               P=position of gradient (0 = beginning of text, 1= end of text)
  24.               C=hexadecimal colour
  25.               A=alpha (opacity) of color (0=invisible,1=opacity 100%)
  26.               Examples :
  27.               for a plain color {{1,0x00FF00,0.5}}
  28.               for a gradient with two colours {{0,0x00FF00,0.5},{1,0x000033,1}}
  29.               or {{0.5,0x00FF00,1},{1,0x000033,1}} -with this one, gradient will start in the middle of the text
  30.               for a gradient with three colours {{0,0x00FF00,0.5},{0.5,0x000033,1},{1,0x440033,1}}
  31.               and so on ...
  32. orientation - in case of gradient, "orientation" defines the starting point of the gradient, default="ww"
  33.               there are 8 available starting points : "nw","nn","ne","ee","se","ss","sw","ww"
  34.               (n for north, w for west ...)
  35.               theses 8 points are the 4 corners + the 4 middles of text's outline
  36.               so a gradient "nn" will go from "nn" to "ss" (top to bottom, parallele to text)
  37.               a gradient "nw" will go from "nw" to "se" (left-top corner to right-bottom corner)
  38. radial      - define a radial gradient (if present at the same time as "orientation", "orientation" will have no effect)
  39.               this parameter is a table with 6 numbers : {xa,ya,ra,xb,yb,rb}
  40.               they define two circle for the gradient :
  41.               xa, ya, xb and yb are relative to x and y values above
  42. reflection_alpha    - add a reflection effect (values from 0 to 1) default = 0 = no reflection
  43.                       other values = starting opacity
  44. reflection_scale    - scale of the reflection (default = 1 = height of text)
  45. reflection_length   - length of reflection, define where the opacity will be set to zero
  46.                       calues from 0 to 1, default =1
  47. skew_x,skew_y    - skew text around x or y axis
  48.              
  49.  
  50. Needs conky 1.8.0
  51.  
  52. To call this script in the conkyrc, in before-TEXT section:
  53.     lua_load /path/to/the/lua/script/text.lua
  54.     lua_draw_hook_pre draw_text
  55.  
  56. v1.0    07/06/2010, Original release
  57. v1.1    10/06/2010  Add "orientation" parameter
  58. v1.2    15/06/2010  Add "h_align", "v_align" and "radial" parameters
  59. v1.3    25/06/2010  Add "reflection_alpha", "reflection_length", "reflection_scale",
  60.                     "skew_x" et "skew_y"
  61.  
  62.  
  63. ]]
  64.  
  65. require 'cairo'
  66.  
  67. function conky_draw_text()
  68.     --DEBUT DES PARAMETRES
  69.     --couleurs utilisées plusieurs fois placées dans des variables
  70.  
  71.     local col0,col1,col2=0x00ffff,0x00ff00,0x0000ff -- 0xFFFFCC,0xCCFF99,0x99FF00
  72.     local colbg=0xffff00--99CCFF
  73.     text_settings={
  74.  
  75.         {
  76.             text="О СИСТЕМЕ...",
  77.             font_name="Ubuntu",
  78.             font_size=16,
  79.             bold=true,
  80.             h_align="l",
  81.             x=0,
  82.             y=20,
  83.             colour={{0,0xc62222,1}},
  84.         },
  85.  
  86.         {
  87.             text=conky_parse("$sysname $kernel"),
  88.             font_name="Ubuntu",
  89.             font_size=14,
  90.             h_align="l",
  91.             x=20,
  92.             y=40,
  93.             colour={{0,0xf0f0f0,1}},
  94.         },
  95.  
  96.         {
  97.             text=conky_parse("$nodename / $user_names"),
  98.             font_name="Ubuntu",
  99.             font_size=14,
  100.             h_align="l",
  101.             x=20,
  102.             y=60,
  103.             colour={{0,0xf0f0f0,1}},
  104.         },
  105.  
  106.         {
  107.             text=conky_parse("В работе: $uptime"),
  108.             font_name="Ubuntu",
  109.             font_size=14,
  110.             h_align="l",
  111.             x=20,
  112.             y=80,
  113.             colour={{0,0xf0f0f0,1}},
  114.         },
  115.  
  116.         {
  117.             text="ЧАСОВЫЕ ПОЯСА",
  118.             font_name="Ubuntu",
  119.             font_size=16,
  120.             bold=true,
  121.             h_align="l",
  122.             x=200,
  123.             y=20,
  124.             colour={{0,0xc62222,1}},
  125.         },
  126.  
  127.         {
  128.             text="UTC",
  129.             font_name="Ubuntu",
  130.             font_size=14,
  131.             h_align="l",
  132.             x=220,
  133.             y=40,
  134.             colour={{0,0xf0f0f0,1}},
  135.         },
  136.  
  137.         {
  138.             text=conky_parse("${tztime UTC %l:%M:%S %P, %d.%m.%y}"),
  139.             font_name="Ubuntu",
  140.             font_size=14,
  141.             h_align="r",
  142.             x=450,
  143.             y=40,
  144.             colour={{0,0xf0f0f0,1}},
  145.         },
  146.  
  147.         {
  148.             text="Киев",
  149.             font_name="Ubuntu",
  150.             font_size=14,
  151.             h_align="l",
  152.             x=220,
  153.             y=60,
  154.             colour={{0,0xf0f0f0,1}},
  155.         },
  156.  
  157.         {
  158.             text=conky_parse("${tztime Europe/Kiev %l:%M:%S %P, %d.%m.%y}"),
  159.             font_name="Ubuntu",
  160.             font_size=14,
  161.             h_align="r",
  162.             x=450,
  163.             y=60,
  164.             colour={{0,0xf0f0f0,1}},
  165.         },
  166.  
  167.         {
  168.             text="Минск",
  169.             font_name="Ubuntu",
  170.             font_size=14,
  171.             h_align="l",
  172.             x=220,
  173.             y=80,
  174.             colour={{0,0xf0f0f0,1}},
  175.         },
  176.  
  177.         {
  178.             text=conky_parse("${tztime Europe/Minsk %l:%M:%S %P, %d.%m.%y}"),
  179.             font_name="Ubuntu",
  180.             font_size=14,
  181.             h_align="r",
  182.             x=450,
  183.             y=80,
  184.             colour={{0,0xf0f0f0,1}},
  185.         },
  186.  
  187.         {
  188.             text="Москва",
  189.             font_name="Ubuntu",
  190.             font_size=14,
  191.             h_align="l",
  192.             x=220,
  193.             y=100,
  194.             colour={{0,0xf0f0f0,1}},
  195.         },
  196.  
  197.         {
  198.             text=conky_parse("${tztime Europe/Moscow %l:%M:%S %P, %d.%m.%y}"),
  199.             font_name="Ubuntu",
  200.             font_size=14,
  201.             h_align="r",
  202.             x=450,
  203.             y=100,
  204.             colour={{0,0xf0f0f0,1}},
  205.         },
  206.  
  207.         {
  208.             text="Баку",
  209.             font_name="Ubuntu",
  210.             font_size=14,
  211.             h_align="l",
  212.             x=220,
  213.             y=120,
  214.             colour={{0,0xf0f0f0,1}},
  215.         },
  216.  
  217.         {
  218.             text=conky_parse("${tztime Asia/Baku %l:%M:%S %P, %d.%m.%y}"),
  219.             font_name="Ubuntu",
  220.             font_size=14,
  221.             h_align="r",
  222.             x=450,
  223.             y=120,
  224.             colour={{0,0xf0f0f0,1}},
  225.         },
  226.  
  227.         {
  228.             text="ЗАГРУЗКА СИСТЕМЫ",
  229.             font_name="Ubuntu",
  230.             font_size=16,
  231.             bold=true,
  232.             h_align="l",
  233.             x=0,
  234.             y=160,
  235.             colour={{0,0xc62222,1}},
  236.         },
  237.  
  238.         {
  239.             text="Процессор",
  240.             font_name="Ubuntu",
  241.             font_size=14,
  242.             h_align="l",
  243.             x=10,
  244.             y=180,
  245.             colour={{0,0x0ca425,1}},
  246.         },
  247.  
  248.         {
  249.             text="Память",
  250.             font_name="Ubuntu",
  251.             font_size=14,
  252.             h_align="l",
  253.             x=300,
  254.             y=180,
  255.             colour={{0,0x0ca425,1}},
  256.         },
  257.  
  258.         {
  259.             text="ПОТРЕБЛЕНИЕ РЕСУРСОВ",
  260.             font_name="Ubuntu",
  261.             font_size=16,
  262.             bold=true,
  263.             h_align="l",
  264.             x=0,
  265.             y=280,
  266.             colour={{0,0xc62222,1}},
  267.         },
  268.  
  269.         {
  270.             text="Процессор",
  271.             font_name="Ubuntu",
  272.             font_size=14,
  273.             h_align="l",
  274.             x=10,
  275.             y=300,
  276.             colour={{0,0x0ca425,1}},
  277.         },
  278.  
  279.         {
  280.             text="Память",
  281.             font_name="Ubuntu",
  282.             font_size=14,
  283.             h_align="l",
  284.             x=235,
  285.             y=300,
  286.             colour={{0,0x0ca425,1}},
  287.         },
  288.  
  289.         {
  290.             text=conky_parse("${top name 1}"),
  291.             font_name="Ubuntu",
  292.             font_size=14,
  293.             h_align="l",
  294.             x=20,
  295.             y=320,
  296.             colour={{0,0xf0f0f0,1}},
  297.         },
  298.  
  299.         {
  300.             text=conky_parse("${top cpu 1}%"),
  301.             font_name="Ubuntu",
  302.             font_size=14,
  303.             h_align="r",
  304.             x=210,
  305.             y=320,
  306.             colour={{0,0xf0f0f0,1}},
  307.         },
  308.  
  309.         {
  310.             text=conky_parse("${top name 2}"),
  311.             font_name="Ubuntu",
  312.             font_size=14,
  313.             h_align="l",
  314.             x=20,
  315.             y=340,
  316.             colour={{0,0xcccccc,1}},
  317.         },
  318.  
  319.         {
  320.             text=conky_parse("${top cpu 2}%"),
  321.             font_name="Ubuntu",
  322.             font_size=14,
  323.             h_align="r",
  324.             x=210,
  325.             y=340,
  326.             colour={{0,0xcccccc,1}},
  327.         },
  328.  
  329.         {
  330.             text=conky_parse("${top name 3}"),
  331.             font_name="Ubuntu",
  332.             font_size=14,
  333.             h_align="l",
  334.             x=20,
  335.             y=360,
  336.             colour={{0,0xa8a8a8,1}},
  337.         },
  338.  
  339.         {
  340.             text=conky_parse("${top cpu 3}%"),
  341.             font_name="Ubuntu",
  342.             font_size=14,
  343.             h_align="r",
  344.             x=210,
  345.             y=360,
  346.             colour={{0,0xa8a8a8,1}},
  347.         },
  348.  
  349.         {
  350.             text=conky_parse("${top name 4}"),
  351.             font_name="Ubuntu",
  352.             font_size=14,
  353.             h_align="l",
  354.             x=20,
  355.             y=380,
  356.             colour={{0,0x999999,1}},
  357.         },
  358.  
  359.         {
  360.             text=conky_parse("${top cpu 4}%"),
  361.             font_name="Ubuntu",
  362.             font_size=14,
  363.             h_align="r",
  364.             x=210,
  365.             y=380,
  366.             colour={{0,0x999999,1}},
  367.         },
  368.  
  369.         {
  370.             text=conky_parse("${top name 5}"),
  371.             font_name="Ubuntu",
  372.             font_size=14,
  373.             h_align="l",
  374.             x=20,
  375.             y=400,
  376.             colour={{0,0x999999,1}},
  377.         },
  378.  
  379.         {
  380.             text=conky_parse("${top cpu 5}%"),
  381.             font_name="Ubuntu",
  382.             font_size=14,
  383.             h_align="r",
  384.             x=210,
  385.             y=400,
  386.             colour={{0,0x999999,1}},
  387.         },
  388.  
  389.         {
  390.             text=conky_parse("${top_mem name 1}"),
  391.             font_name="Ubuntu",
  392.             font_size=14,
  393.             h_align="l",
  394.             x=245,
  395.             y=320,
  396.             colour={{0,0xf0f0f0,1}},
  397.         },
  398.  
  399.         {
  400.             text=conky_parse("${top_mem mem 1}%"),
  401.             font_name="Ubuntu",
  402.             font_size=14,
  403.             h_align="r",
  404.             x=445,
  405.             y=320,
  406.             colour={{0,0xf0f0f0,1}},
  407.         },
  408.  
  409.         {
  410.             text=conky_parse("${top_mem name 2}"),
  411.             font_name="Ubuntu",
  412.             font_size=14,
  413.             h_align="l",
  414.             x=245,
  415.             y=340,
  416.             colour={{0,0xcccccc,1}},
  417.         },
  418.  
  419.         {
  420.             text=conky_parse("${top_mem mem 2}%"),
  421.             font_name="Ubuntu",
  422.             font_size=14,
  423.             h_align="r",
  424.             x=445,
  425.             y=340,
  426.             colour={{0,0xcccccc,1}},
  427.         },
  428.  
  429.         {
  430.             text=conky_parse("${top_mem name 3}"),
  431.             font_name="Ubuntu",
  432.             font_size=14,
  433.             h_align="l",
  434.             x=245,
  435.             y=360,
  436.             colour={{0,0xa8a8a8,1}},
  437.         },
  438.  
  439.         {
  440.             text=conky_parse("${top_mem mem 3}%"),
  441.             font_name="Ubuntu",
  442.             font_size=14,
  443.             h_align="r",
  444.             x=445,
  445.             y=360,
  446.             colour={{0,0xa8a8a8,1}},
  447.         },
  448.  
  449.         {
  450.             text=conky_parse("${top_mem name 4}"),
  451.             font_name="Ubuntu",
  452.             font_size=14,
  453.             h_align="l",
  454.             x=245,
  455.             y=380,
  456.             colour={{0,0x999999,1}},
  457.         },
  458.  
  459.         {
  460.             text=conky_parse("${top_mem mem 4}%"),
  461.             font_name="Ubuntu",
  462.             font_size=14,
  463.             h_align="r",
  464.             x=445,
  465.             y=380,
  466.             colour={{0,0x999999,1}},
  467.         },
  468.  
  469.         {
  470.             text=conky_parse("${top_mem name 5}"),
  471.             font_name="Ubuntu",
  472.             font_size=14,
  473.             h_align="l",
  474.             x=245,
  475.             y=400,
  476.             colour={{0,0x999999,1}},
  477.         },
  478.  
  479.         {
  480.             text=conky_parse("${top_mem mem 5}%"),
  481.             font_name="Ubuntu",
  482.             font_size=14,
  483.             h_align="r",
  484.             x=445,
  485.             y=400,
  486.             colour={{0,0x999999,1}},
  487.         },
  488.  
  489.         {
  490.             text="ИСПОЛЬЗОВАНИЕ СЕТИ",
  491.             font_name="Ubuntu",
  492.             font_size=16,
  493.             bold=true,
  494.             h_align="l",
  495.             x=0,
  496.             y=420,
  497.             colour={{0,0xc62222,1}},
  498.         },
  499.  
  500.         {
  501.             text="Eth0",
  502.             font_name="Ubuntu",
  503.             font_size=14,
  504.             h_align="l",
  505.             x=10,
  506.             y=440,
  507.             colour={{0,0x0ca425,1}},
  508.         },
  509.  
  510.         {
  511.             text=conky_parse("Приём: ${downspeed eth0}"),
  512.             font_name="Ubuntu",
  513.             font_size=14,
  514.             h_align="l",
  515.             x=20,
  516.             y=460,
  517.             colour={{0,0xf0f0f0,1}},
  518.         },
  519.  
  520.         {
  521.             text=conky_parse("Всего принято: ${totaldown}"),
  522.             font_name="Ubuntu",
  523.             font_size=14,
  524.             h_align="r",
  525.             x=450,
  526.             y=460,
  527.             colour={{0,0xf0f0f0,1}},
  528.         },
  529.  
  530.         {
  531.             text=conky_parse("Передача: ${upspeed eth0}"),
  532.             font_name="Ubuntu",
  533.             font_size=14,
  534.             h_align="l",
  535.             x=20,
  536.             y=480,
  537.             colour={{0,0xf0f0f0,1}},
  538.         },
  539.  
  540.         {
  541.             text=conky_parse("Всего передано: ${totalup}"),
  542.             font_name="Ubuntu",
  543.             font_size=14,
  544.             h_align="r",
  545.             x=450,
  546.             y=480,
  547.             colour={{0,0xf0f0f0,1}},
  548.         },
  549.  
  550.         {
  551.             text="ИСПОЛЬЗОВАНИЕ ДИСКОВ",
  552.             font_name="Ubuntu",
  553.             font_size=16,
  554.             bold=true,
  555.             h_align="l",
  556.             x=0,
  557.             y=500,
  558.             colour={{0,0xc62222,1}},
  559.         },
  560.  
  561.         {
  562.             text="/",
  563.             font_name="Ubuntu",
  564.             font_size=14,
  565.             h_align="l",
  566.             x=75,
  567.             y=520,
  568.             colour={{0,0xf0f0f0,1}},
  569.         },
  570.  
  571.         {
  572.             text="/home",
  573.             font_name="Ubuntu",
  574.             font_size=14,
  575.             h_align="l",
  576.             x=225,
  577.             y=520,
  578.             colour={{0,0xf0f0f0,1}},
  579.         },
  580.  
  581.         {
  582.             text="userdata",
  583.             font_name="Ubuntu",
  584.             font_size=14,
  585.             h_align="l",
  586.             x=375,
  587.             y=520,
  588.             colour={{0,0xf0f0f0,1}},
  589.         },
  590.  
  591.         {
  592.             text=conky_parse("${fs_used_perc /}%"),
  593.             font_name="Ubuntu",
  594.             font_size=14,
  595.             h_align="c",
  596.             x=40,
  597.             y=548,
  598.             colour={{0,0xf0f0f0,1}},
  599.         },
  600.  
  601.         {
  602.             text=conky_parse("${fs_used_perc /home}%"),
  603.             font_name="Ubuntu",
  604.             font_size=14,
  605.             h_align="c",
  606.             x=190,
  607.             y=548,
  608.             colour={{0,0xf0f0f0,1}},
  609.         },
  610.  
  611.         {
  612.             text=conky_parse("${fs_used_perc /mnt/userdata}%"),
  613.             font_name="Ubuntu",
  614.             font_size=14,
  615.             h_align="c",
  616.             x=340,
  617.             y=548,
  618.             colour={{0,0xf0f0f0,1}},
  619.         },
  620.  
  621.         {
  622.             text=conky_parse("Всего: ${fs_size /}"),
  623.             font_name="Ubuntu",
  624.             font_size=12,
  625.             h_align="l",
  626.             x=60,
  627.             y=560,
  628.             colour={{0,0xf0f0f0,1}},
  629.         },
  630.  
  631.         {
  632.             text=conky_parse("Занято: ${fs_used /}"),
  633.             font_name="Ubuntu",
  634.             font_size=12,
  635.             h_align="l",
  636.             x=60,
  637.             y=575,
  638.             colour={{0,0xf0f0f0,1}},
  639.         },
  640.  
  641.         {
  642.             text=conky_parse("Всего: ${fs_size /home}"),
  643.             font_name="Ubuntu",
  644.             font_size=12,
  645.             h_align="l",
  646.             x=210,
  647.             y=560,
  648.             colour={{0,0xf0f0f0,1}},
  649.         },
  650.  
  651.         {
  652.             text=conky_parse("Занято: ${fs_used /home}"),
  653.             font_name="Ubuntu",
  654.             font_size=12,
  655.             h_align="l",
  656.             x=210,
  657.             y=575,
  658.             colour={{0,0xf0f0f0,1}},
  659.         },
  660.  
  661.         {
  662.             text=conky_parse("Всего: ${fs_size /mnt/userdata}"),
  663.             font_name="Ubuntu",
  664.             font_size=12,
  665.             h_align="l",
  666.             x=360,
  667.             y=560,
  668.             colour={{0,0xf0f0f0,1}},
  669.         },
  670.  
  671.         {
  672.             text=conky_parse("Занято: ${fs_used /mnt/userdata}"),
  673.             font_name="Ubuntu",
  674.             font_size=12,
  675.             h_align="l",
  676.             x=360,
  677.             y=575,
  678.             colour={{0,0xf0f0f0,1}},
  679.         },
  680.  
  681.     }
  682.    
  683. --------------FIN DES PARAMETERES----------------
  684.     if conky_window == nil then return end
  685.     if tonumber(conky_parse("$updates"))<3 then return end
  686.    
  687.     local cs = cairo_xlib_surface_create(conky_window.display, conky_window.drawable, conky_window.visual, conky_window.width, conky_window.height)
  688.  
  689.     for i,v in pairs(text_settings) do 
  690.         cr = cairo_create (cs)
  691.         display_text(v)
  692.         cairo_destroy(cr)
  693.     end
  694.    
  695.     cairo_surface_destroy(cs)
  696.    
  697.  
  698.  
  699. end
  700.  
  701. function rgb_to_r_g_b2(tcolour)
  702.     colour,alpha=tcolour[2],tcolour[3]
  703.     return ((colour / 0x10000) % 0x100) / 255., ((colour / 0x100) % 0x100) / 255., (colour % 0x100) / 255., alpha
  704. end
  705.  
  706. function display_text(t)
  707.  
  708.     local function set_pattern()
  709.         --this function set the pattern
  710.         if #t.colour==1 then
  711.             cairo_set_source_rgba(cr,rgb_to_r_g_b2(t.colour[1]))
  712.         else
  713.             local pat
  714.            
  715.             if t.radial==nil then
  716.                 local pts=linear_orientation(t,te)
  717.                 pat = cairo_pattern_create_linear (pts[1],pts[2],pts[3],pts[4])
  718.             else
  719.                 pat = cairo_pattern_create_radial (t.radial[1],t.radial[2],t.radial[3],t.radial[4],t.radial[5],t.radial[6])
  720.             end
  721.        
  722.             for i=1, #t.colour do
  723.                 cairo_pattern_add_color_stop_rgba (pat, t.colour[i][1], rgb_to_r_g_b2(t.colour[i]))
  724.             end
  725.             cairo_set_source (cr, pat)
  726.         end
  727.     end
  728.    
  729.     --set default values if needed
  730.     if t.text==nil then t.text="Conky is good for you !" end
  731.     if t.x==nil then t.x = conky_window.width/2 end
  732.     if t.y==nil then t.y = conky_window.height/2 end
  733.     if t.colour==nil then t.colour={{1,0xFFFFFF,1}} end
  734.     if t.font_name==nil then t.font_name="Free Sans" end
  735.     if t.font_size==nil then t.font_size=14 end
  736.     if t.angle==nil then t.angle=0 end
  737.     if t.italic==nil then t.italic=false end
  738.     if t.oblique==nil then t.oblique=false end
  739.     if t.bold==nil then t.bold=false end
  740.     if t.radial ~= nil then
  741.         if #t.radial~=6 then
  742.             print ("error in radial table")
  743.             t.radial=nil
  744.         end
  745.     end
  746.     if t.orientation==nil then t.orientation="ww" end
  747.     if t.h_align==nil then t.h_align="l" end
  748.     if t.v_align==nil then t.v_align="b" end    
  749.     if t.reflection_alpha == nil then t.reflection_alpha=0 end
  750.     if t.reflection_length == nil then t.reflection_length=1 end
  751.     if t.reflection_scale == nil then t.reflection_scale=1 end
  752.     if t.rotx==nil then t.rotx=0 end
  753.     if t.roty==nil then t.roty=0 end    
  754.     cairo_translate(cr,t.x,t.y)
  755.     cairo_rotate(cr,t.angle*math.pi/180)
  756.     cairo_save(cr)      
  757.    
  758.  
  759.  
  760.     local slant = CAIRO_FONT_SLANT_NORMAL
  761.     local weight =CAIRO_FONT_WEIGHT_NORMAL
  762.     if t.italic then slant = CAIRO_FONT_SLANT_ITALIC end
  763.     if t.oblique then slant = CAIRO_FONT_SLANT_OBLIQUE end
  764.     if t.bold then weight = CAIRO_FONT_WEIGHT_BOLD end
  765.    
  766.     cairo_select_font_face(cr, t.font_name, slant,weight)
  767.  
  768.     for i=1, #t.colour do    
  769.         if #t.colour[i]~=3 then
  770.             print ("error in color table")
  771.             t.colour[i]={1,0xFFFFFF,1}
  772.         end
  773.     end
  774.  
  775.     local matrix0 = cairo_matrix_t:create()
  776.     rotx,roty=t.rotx/t.font_size,t.roty/t.font_size
  777.     cairo_matrix_init (matrix0, 1,roty,rotx,1,0,0)
  778.     cairo_transform(cr,matrix0)
  779.     cairo_set_font_size(cr,t.font_size)
  780.     te=cairo_text_extents_t:create()
  781.     cairo_text_extents (cr,t.text,te)
  782.    
  783.     set_pattern()
  784.  
  785.  
  786.            
  787.     mx,my=0,0
  788.    
  789.     if t.h_align=="c" then
  790.         mx=-te.width/2
  791.     elseif t.h_align=="r" then
  792.         mx=-te.width
  793.     end
  794.     if t.v_align=="m" then
  795.         my=-te.height/2-te.y_bearing
  796.     elseif t.v_align=="t" then
  797.         my=-te.y_bearing
  798.     end
  799.     cairo_move_to(cr,mx,my)
  800.    
  801.     cairo_show_text(cr,t.text)
  802.  
  803.    
  804.        
  805.        
  806.    if t.reflection_alpha ~= 0 then
  807.         local matrix1 = cairo_matrix_t:create()
  808.         cairo_set_font_size(cr,t.font_size)
  809.  
  810.         cairo_matrix_init (matrix1,1,0,0,-1*t.reflection_scale,0,(te.height+te.y_bearing+my)*(1+t.reflection_scale))
  811.         cairo_set_font_size(cr,t.font_size)
  812.         te=cairo_text_extents_t:create()
  813.         cairo_text_extents (cr,t.text,te)
  814.        
  815.                
  816.         cairo_transform(cr,matrix1)
  817.         set_pattern()
  818.         cairo_move_to(cr,mx,my)
  819.         cairo_show_text(cr,t.text)
  820.  
  821.  
  822.         local pat2 = cairo_pattern_create_linear (0,
  823.                                         (te.y_bearing+te.height+my),
  824.                                         0,
  825.                                         te.y_bearing+my)
  826.         cairo_pattern_add_color_stop_rgba (pat2, 0,1,0,0,1-t.reflection_alpha)
  827.         cairo_pattern_add_color_stop_rgba (pat2, t.reflection_length,0,0,0,1)  
  828.        
  829.        
  830.         cairo_set_line_width(cr,0)
  831.         dy=te.x_bearing
  832.         if dy<0 then dy=dy*(-1) end
  833.         cairo_rectangle(cr,mx+te.x_bearing,te.y_bearing+te.height+my,te.width+dy,-te.height*1.05)
  834.         cairo_clip_preserve(cr)
  835.         cairo_set_operator(cr,CAIRO_OPERATOR_CLEAR)
  836.         --cairo_stroke(cr)
  837.         cairo_mask(cr,pat2)
  838.         cairo_pattern_destroy(pat2)
  839.         cairo_set_operator(cr,CAIRO_OPERATOR_OVER)
  840.     end
  841.    
  842. end
  843.  
  844.  
  845. function linear_orientation(t,te)
  846.     local w,h=te.width,te.height
  847.     local xb,yb=te.x_bearing,te.y_bearing
  848.    
  849.     if t.h_align=="c" then
  850.         xb=xb-w/2
  851.     elseif t.h_align=="r" then
  852.         xb=xb-w
  853.     end
  854.     if t.v_align=="m" then
  855.         yb=-h/2
  856.     elseif t.v_align=="t" then
  857.         yb=0
  858.     end
  859.    
  860.     if t.orientation=="nn" then
  861.         p={xb+w/2,yb,xb+w/2,yb+h}
  862.     elseif t.orientation=="ne" then
  863.         p={xb+w,yb,xb,yb+h}
  864.     elseif t.orientation=="ww" then
  865.         p={xb,h/2,xb+w,h/2}
  866.     elseif vorientation=="se" then
  867.         p={xb+w,yb+h,xb,yb}
  868.     elseif t.orientation=="ss" then
  869.         p={xb+w/2,yb+h,xb+w/2,yb}
  870.     elseif vorientation=="ee" then
  871.         p={xb+w,h/2,xb,h/2}    
  872.     elseif t.orientation=="sw" then
  873.         p={xb,yb+h,xb+w,yb}
  874.     elseif t.orientation=="nw" then
  875.         p={xb,yb,xb+w,yb+h}
  876.     end
  877.     return p
  878. end
Advertisement
Add Comment
Please, Sign In to add comment