[Solved] Colorize Text Phrase as a GRADIENT?

Discuss the word processor
Post Reply
User avatar
semicodin
Posts: 32
Joined: Fri Jun 20, 2014 11:18 pm

[Solved] Colorize Text Phrase as a GRADIENT?

Post by semicodin »

For example, I have a phrase I would like to begin with the font color in BLACK and end with the font color in BLUE.

I'm not certain where to post this so (as is usually the case with me) move it where it belongs. :mrgreen:
Last edited by MrProgrammer on Sat Dec 19, 2020 5:38 am, edited 1 time in total.
Reason: Tagged ✓ [Solved]
WINDOWS XP PRO
WINDOWS 7 PRO 64-BIT [Currently Building]
APACHE OPEN OFFICE ver. 4.1.0
User avatar
MrProgrammer
Moderator
Posts: 5280
Joined: Fri Jun 04, 2010 7:57 pm
Location: Wisconsin, USA

Re: Colorize Text Phrase as a GRADIENT?

Post by MrProgrammer »

Intersect fontwork containing the text with an area filled with a gradient.

If this answered your question please go to your first post use the Edit button and add [Solved] to the start of the title. You can select the green checkmark icon at the same time.
Attachments
201506261852.odg
(12.87 KiB) Downloaded 234 times
Mr. Programmer
AOO 4.1.7 Build 9800, MacOS 13.7.6, iMac Intel.   The locale for any menus or Calc formulas in my posts is English (USA).
User avatar
semicodin
Posts: 32
Joined: Fri Jun 20, 2014 11:18 pm

Re: Colorize Text Phrase as a GRADIENT?

Post by semicodin »

MrProgrammer I'm not sure how you did that in Writer. Here's the actual file. Here's a stripped-down Forum-Friendly version. Just as in your example, the text is a L to R gradient from BLACK to BLUE. Thank you so much.
BECOMES.odt
(9.52 KiB) Downloaded 237 times
WINDOWS XP PRO
WINDOWS 7 PRO 64-BIT [Currently Building]
APACHE OPEN OFFICE ver. 4.1.0
F3K Total
Volunteer
Posts: 1044
Joined: Fri Dec 16, 2011 8:20 pm

Re: Colorize Text Phrase as a GRADIENT?

Post by F3K Total »

gradient.PNG
R
Attachments
BECOMES.odt
(16.71 KiB) Downloaded 223 times
  • MMove 1.0.6
  • Extension for easy, exact positioning of shapes, pictures, controls, frames ...
  • my current system
  • Windows 11 AOO, LO | Linux Mint AOO, LO
User avatar
Zizi64
Volunteer
Posts: 11481
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: Colorize Text Phrase as a GRADIENT?

Post by Zizi64 »

Here is an another approach based on macros.
The previous solutions will put a graphical object into a textual document.
My macro (running in a Calc application), will colorize a text (letter by letter) with colors calculated from the adjusted gradient limits. After formatting you can paste it into a text line like the normal formatted strings...
Gradient color3.ods
(21.59 KiB) Downloaded 464 times
 Edit: Tested and modified with Libreoffice 4.4.4 
Tibor Kovacs, Hungary; LO7.5.8 /Win7-10 x64Prof.
PortableApps/winPenPack: LO3.3.0-7.6.2;AOO4.1.14
Please, edit the initial post in the topic: add the word [Solved] at the beginning of the subject line - if your problem has been solved.
cegri
Posts: 3
Joined: Thu Mar 01, 2018 11:03 am

Re: Colorize Text Phrase as a GRADIENT?

Post by cegri »

Zizi64's macro is very close to what I'm seeking, so I'll post here:

I need a similar macro that will format within the selected cell.
If the selected cell has multiple lines, the first line will be left at 12px regular font. The rest of the cell shall be formated to 10pc italic font. Single line cells are left as 12 px regular fonts.
So the macro will go through each character in the cell, use font A until the first line feed, than B for the rest.

The macro will be used to format a template that has a few hundred products. The template will then be used by a couple of people to prepare quotations. Using multiple cells is not preferred to avoid copy/paste errors
Attachments
Sample.ods
File showing the unformatted cell and the requested format
(33.31 KiB) Downloaded 162 times
LibreOffice 5.4 on Windows 10
User avatar
Zizi64
Volunteer
Posts: 11481
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: Colorize Text Phrase as a GRADIENT?

Post by Zizi64 »

I suggested for you in a PM:

"It is not a good idea (really it is wrong idea) to format differenly the text lines in a cell. Use more than one cell with different CellStyles, and near the cells use combined (merged) cells. Those will be appeared as a single cell, and use white (or other colorized) background for the differently formatted cells: they will appeares similarly to a single cell."

your answer was:
"I prefer not to use separate cells to avoid copy / paste errors."

My Tip now:
Then use the suggested method, and write a simple macro for the copy/paste procedure...
Tibor Kovacs, Hungary; LO7.5.8 /Win7-10 x64Prof.
PortableApps/winPenPack: LO3.3.0-7.6.2;AOO4.1.14
Please, edit the initial post in the topic: add the word [Solved] at the beginning of the subject line - if your problem has been solved.
cegri
Posts: 3
Joined: Thu Mar 01, 2018 11:03 am

Re: Colorize Text Phrase as a GRADIENT?

Post by cegri »

Below is the code I ended up with, tweaking Zizi64's code.

This only formats the current cell.

Could someone point me to the simplest method for repeating this for all the cells in the current selection.

Like;
For (each cell in currentselection as x){
// do stuff on x;
}

Code: Select all

sub FormatProductDescription
rem ----------------------------------------------------------------------
rem define variables
dim document   as object
dim dispatcher as object
dim args1(0) as new com.sun.star.beans.PropertyValue
dim args2(0) as new com.sun.star.beans.PropertyValue
dim args3(0) as new com.sun.star.beans.PropertyValue
dim args4(1) as new com.sun.star.beans.PropertyValue
dim PositionOfEnter as Long
rem ----------------------------------------------------------------------
rem get access to the document
document   = ThisComponent.CurrentController.Frame
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")

rem ----RESET FORMAT TO DEFAULT STYLE
dispatcher.executeDispatch(document, ".uno:ResetAttributes", "", 0, Array())

rem ----APPLY FORMAT
oCell = ThisComponent.getCurrentSelection() 

TextContent = oCell.string
PositionOfEnter = InStr(TextContent, chr(10))

if PositionOfEnter > 0 then
	args1(0).Name = "Symbols"

	args2(0).Name = "FontHeight.Height"
	args2(0).Value = 10

	args3(0).Name = "Italic"
	args3(0).Value = true
	
	args1(0).Value = Left(TextContent, PositionOfEnter)
	dispatcher.executeDispatch(document, ".uno:InsertSymbol", "", 0, args1())

	dispatcher.executeDispatch(document, ".uno:FontHeight", "", 0, args2())
	dispatcher.executeDispatch(document, ".uno:Italic", "", 0, args3())	

	args1(0).Value = Mid(TextContent, PositionOfEnter)
	dispatcher.executeDispatch(document, ".uno:InsertSymbol", "", 0, args1())

end if

	args4(0).Name = "By"
	args4(0).Value = 1
	args4(1).Name = "Sel"
	args4(1).Value = false

	dispatcher.executeDispatch(document, ".uno:GoDown", "", 0, args4())

end sub
LibreOffice 5.4 on Windows 10
Post Reply