Method: TCPDF#SetTextColor
- Defined in:
- lib/tcpdf.rb
#SetTextColor(col1 = 0, col2 = -1,, col3 = -1,, col4 = -1)) ⇒ Object Also known as: set_text_color
Defines the color used for text. It can be expressed in RGB components or gray scale. The method can be called before the first page is created and the value is retained from page to page.
- @param int :col1
-
Gray level for single color, or Red color for RGB, or Cyan color for CMYK. Value between 0 and 255
- @param int :col2
-
Green color for RGB, or Magenta color for CMYK. Value between 0 and 255
- @param int :col3
-
Blue color for RGB, or Yellow color for CMYK. Value between 0 and 255
- @param int :col4
-
Key (Black) color for CMYK. Value between 0 and 255
- @access public
- @since 1.3
- @see
-
SetDrawColor(), SetFillColor(), Text(), Cell(), MultiCell()
2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 |
# File 'lib/tcpdf.rb', line 2351 def SetTextColor(col1=0, col2=-1, col3=-1, col4=-1) # set default values unless col1.is_a?(Numeric) col1 = 0 end unless col2.is_a?(Numeric) col2 = -1 end unless col3.is_a?(Numeric) col3 = -1 end unless col4.is_a?(Numeric) col4 = -1 end # Set color for text if (col2 == -1) and (col3 == -1) and (col4 == -1) # Grey scale @text_color = sprintf('%.3f g', col1 / 255.0) @fgcolor['G'] = col1 elsif col4 == -1 # RGB @text_color = sprintf('%.3f %.3f %.3f rg', col1 / 255.0, col2 / 255.0, col3 / 255.0) @fgcolor['R'] = col1 @fgcolor['G'] = col2 @fgcolor['B'] = col3 else # CMYK @text_color = sprintf('%.3f %.3f %.3f %.3f k', col1 / 100.0, col2 / 100.0, col3 / 100.0, col4 / 100.0) @fgcolor['C'] = col1 @fgcolor['M'] = col2 @fgcolor['Y'] = col3 @fgcolor['K'] = col4 end @color_flag = (@fill_color != @text_color) end |