-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathLibreOffice_Helper.au3
More file actions
1564 lines (1290 loc) · 85.4 KB
/
LibreOffice_Helper.au3
File metadata and controls
1564 lines (1290 loc) · 85.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7
#Tidy_Parameters=/sf /reel /tcl=1
#include-once
#include "LibreOffice_Constants.au3"
#include "LibreOffice_Internal.au3"
; #INDEX# =======================================================================================================================
; Title .........: LibreOffice UDF
; AutoIt Version : v3.3.16.1
; Description ...: Helper functions for using this UDF.
; Author(s) .....: donnyh13, mLipok
; Dll ...........:
;
; ===============================================================================================================================
; #CURRENT# =====================================================================================================================
; _LO_ComError_UserFunction
; _LO_ConvertColorFromLong
; _LO_ConvertColorToLong
; _LO_DocConnect
; _LO_DocGetType
; _LO_GradientMulticolorAdd
; _LO_GradientMulticolorDelete
; _LO_GradientMulticolorModify
; _LO_InitializePortable
; _LO_PathConvert
; _LO_PrintersGetNames
; _LO_PrintersGetNamesAlt
; _LO_Terminate
; _LO_TransparencyGradientMultiAdd
; _LO_TransparencyGradientMultiDelete
; _LO_TransparencyGradientMultiModify
; _LO_UnitConvert
; _LO_VersionGet
; ===============================================================================================================================
; #FUNCTION# ====================================================================================================================
; Name ..........: _LO_ComError_UserFunction
; Description ...: Set a UserFunction to receive the Fired COM Error Error outside of the UDF.
; Syntax ........: _LO_ComError_UserFunction([$vUserFunction = Default[, $vParam1 = Null[, $vParam2 = Null[, $vParam3 = Null[, $vParam4 = Null[, $vParam5 = Null]]]]]])
; Parameters ....: $vUserFunction - [optional] a Function or Keyword. Default is Default. Accepts a Function, or the Keyword Default and Null. If called with a User function, the function may have up to 5 required parameters.
; $vParam1 - [optional] a variant value. Default is Null. Any optional parameter to be called with the user function.
; $vParam2 - [optional] a variant value. Default is Null. Any optional parameter to be called with the user function.
; $vParam3 - [optional] a variant value. Default is Null. Any optional parameter to be called with the user function.
; $vParam4 - [optional] a variant value. Default is Null. Any optional parameter to be called with the user function.
; $vParam5 - [optional] a variant value. Default is Null. Any optional parameter to be called with the user function.
; Return values .: Success: 1 or UserFunction.
; Failure: 0 and sets the @Error and @Extended flags to non-zero.
; --Input Errors--
; @Error 1 @Extended 1 Return 0 = $vUserFunction Not a Function, or Default keyword, or Null Keyword.
; --Success--
; @Error 0 @Extended 0 Return 1 = Successfully set the UserFunction.
; @Error 0 @Extended 0 Return 2 = Successfully cleared the set UserFunction.
; @Error 0 @Extended 0 Return Function = Returning the set UserFunction.
; Author ........: mLipok
; Modified ......: donnyh13 - Added a clear UserFunction without error option. Also added parameters option.
; Remarks .......: The first parameter passed to the User function will always be the COM Error object. See below.
; Every COM Error will be passed to that function. The user can then read the following properties. (As Found in the COM Reference section in AutoIt Help File.) Using the first parameter in the UserFunction.
; For Example MyFunc($oMyError)
; - $oMyError.number The Windows HRESULT value from a COM call
; - $oMyError.windescription The FormatWinError() text derived from .number
; - $oMyError.source Name of the Object generating the error (contents from ExcepInfo.source)
; - $oMyError.description Source Object's description of the error (contents from ExcepInfo.description)
; - $oMyError.helpfile Source Object's help file for the error (contents from ExcepInfo.helpfile)
; - $oMyError.helpcontext Source Object's help file context id number (contents from ExcepInfo.helpcontext)
; - $oMyError.lastdllerror The number returned from GetLastError()
; - $oMyError.scriptline The script line on which the error was generated
; - NOTE: Not all properties will necessarily contain data, some will be blank.
; If MsgBox or ConsoleWrite functions are passed to this function, the error details will be displayed using that function automatically.
; If called with Default keyword, the current UserFunction, if set, will be returned.
; If called with Null keyword, the currently set UserFunction is cleared and only the internal ComErrorHandler will be called for COM Errors.
; The stored UserFunction (besides MsgBox and ConsoleWrite) will be called as follows: UserFunc($oComError,$vParam1,$vParam2,$vParam3,$vParam4,$vParam5)
; Related .......:
; Link ..........:
; Example .......: Yes
; ===============================================================================================================================
Func _LO_ComError_UserFunction($vUserFunction = Default, $vParam1 = Null, $vParam2 = Null, $vParam3 = Null, $vParam4 = Null, $vParam5 = Null)
#forceref $vParam1, $vParam2, $vParam3, $vParam4, $vParam5
; If user does not set a function, UDF must use internal function to avoid AutoItError.
Local Static $vUserFunction_Static = Default
Local $avUserFuncWParams[@NumParams]
If $vUserFunction = Default Then
; just return stored static User Function variable
Return SetError($__LO_STATUS_SUCCESS, 0, $vUserFunction_Static)
ElseIf IsFunc($vUserFunction) Then
; If User called Parameters, then add to array.
If @NumParams > 1 Then
$avUserFuncWParams[0] = $vUserFunction
For $i = 1 To @NumParams - 1
$avUserFuncWParams[$i] = Eval("vParam" & $i)
; set static variable
Next
$vUserFunction_Static = $avUserFuncWParams
Else
$vUserFunction_Static = $vUserFunction
EndIf
Return SetError($__LO_STATUS_SUCCESS, 0, 1)
ElseIf $vUserFunction = Null Then
; Clear User Function.
$vUserFunction_Static = Default
Return SetError($__LO_STATUS_SUCCESS, 0, 2)
Else
; return error as an incorrect parameter was passed to this function
Return SetError($__LO_STATUS_INPUT_ERROR, 1, 0)
EndIf
EndFunc ;==>_LO_ComError_UserFunction
; #FUNCTION# ====================================================================================================================
; Name ..........: _LO_ConvertColorFromLong
; Description ...: Convert a RGB Color Integer to Hex, RGB, HSB or CMYK.
; Syntax ........: _LO_ConvertColorFromLong([$iHex = Null[, $iRGB = Null[, $iHSB = Null[, $iCMYK = Null]]]])
; Parameters ....: $iHex - [optional] an integer value. Default is Null. Convert a RGB Color Integer to Hexadecimal.
; $iRGB - [optional] an integer value. Default is Null. Convert a RGB Color Integer to R.G.B.
; $iHSB - [optional] an integer value. Default is Null. Convert a RGB Color Integer to H.S.B.
; $iCMYK - [optional] an integer value. Default is Null. Convert a RGB Color Integer to C.M.Y.K.
; Return values .: Success: String or Array.
; Failure: 0 and sets the @Error and @Extended flags to non-zero.
; --Input Errors--
; @Error 1 @Extended 1 Return 0 = No parameters set.
; @Error 1 @Extended 2 Return 0 = No parameters called with an Integer.
; --Success--
; @Error 0 @Extended 1 Return String = RGB Integer converted To Hexadecimal (as a String). (Without the "0x" prefix)
; @Error 0 @Extended 2 Return Array = Array containing RGB Integer converted To Red, Green, Blue,(RGB). $Array[0] = R, $Array[1] = G, etc.
; @Error 0 @Extended 3 Return Array = Array containing RGB Integer converted To Hue, Saturation, Brightness, (HSB). $Array[0] = H, $Array[1] = S, etc.
; @Error 0 @Extended 4 Return Array = Array containing RGB Integer converted To Cyan, Magenta, Yellow, Black, (CMYK). $Array[0] = C, $Array[1] = M, etc.
; Author ........: donnyh13
; Modified ......:
; Remarks .......: To retrieve a Hexadecimal color value, call the RGB Color Integer in $iHex, To retrieve a R(ed)G(reen)B(lue) color value, call Null in $iHex, and call the RGB Color Integer into $iRGB, etc. for the other color types.
; Hex returns as a string variable, all others (RGB, HSB, CMYK) return an array.
; The Hexadecimal figure returned doesn't contain the usual "0x", as LibreOffice does not implement it in its numbering system.
; Related .......: _LO_ConvertColorToLong
; Link ..........:
; Example .......: Yes
; ===============================================================================================================================
Func _LO_ConvertColorFromLong($iHex = Null, $iRGB = Null, $iHSB = Null, $iCMYK = Null)
Local $nRed, $nGreen, $nBlue, $nResult, $nMaxRGB, $nMinRGB, $nHue, $nSaturation, $nBrightness, $nCyan, $nMagenta, $nYellow, $nBlack
Local $dHex
Local $aiReturn[0]
If (@NumParams = 0) Then Return SetError($__LO_STATUS_INPUT_ERROR, 1, 0)
Select
Case IsInt($iHex) ; Long TO Hex
$nRed = BitAND(BitShift($iHex, 16), 0xff)
$nGreen = BitAND(BitShift($iHex, 8), 0xff)
$nBlue = BitAND($iHex, 0xff)
$dHex = Hex($nRed, 2) & Hex($nGreen, 2) & Hex($nBlue, 2)
Return SetError($__LO_STATUS_SUCCESS, 1, $dHex)
Case IsInt($iRGB) ; Long to RGB
$nRed = BitAND(BitShift($iRGB, 16), 0xff)
$nGreen = BitAND(BitShift($iRGB, 8), 0xff)
$nBlue = BitAND($iRGB, 0xff)
ReDim $aiReturn[3]
$aiReturn[0] = $nRed
$aiReturn[1] = $nGreen
$aiReturn[2] = $nBlue
Return SetError($__LO_STATUS_SUCCESS, 2, $aiReturn)
Case IsInt($iHSB) ; Long to HSB
$nRed = (Mod(($iHSB / 65536), 256) / 255)
$nGreen = (Mod(($iHSB / 256), 256) / 255)
$nBlue = (Mod($iHSB, 256) / 255)
; get Max RGB Value
$nResult = ($nRed > $nGreen) ? ($nRed) : ($nGreen)
$nMaxRGB = ($nResult > $nBlue) ? ($nResult) : ($nBlue)
; get Min RGB Value
$nResult = ($nRed < $nGreen) ? ($nRed) : ($nGreen)
$nMinRGB = ($nResult < $nBlue) ? ($nResult) : ($nBlue)
; Determine Brightness
$nBrightness = $nMaxRGB
; Determine Hue
$nHue = 0
Select
Case $nRed = $nGreen = $nBlue ; Red, Green, and Blue are equal.
$nHue = 0
Case ($nRed >= $nGreen) And ($nGreen >= $nBlue) ; Red Highest, Blue Lowest
$nHue = (60 * (($nGreen - $nBlue) / ($nRed - $nBlue)))
Case ($nRed >= $nBlue) And ($nBlue >= $nGreen) ; Red Highest, Green Lowest
$nHue = (60 * (6 - (($nBlue - $nGreen) / ($nRed - $nGreen))))
Case ($nGreen >= $nRed) And ($nRed >= $nBlue) ; Green Highest, Blue Lowest
$nHue = (60 * (2 - (($nRed - $nBlue) / ($nGreen - $nBlue))))
Case ($nGreen >= $nBlue) And ($nBlue >= $nRed) ; Green Highest, Red Lowest
$nHue = (60 * (2 + (($nBlue - $nRed) / ($nGreen - $nRed))))
Case ($nBlue >= $nGreen) And ($nGreen >= $nRed) ; Blue Highest, Red Lowest
$nHue = (60 * (4 - (($nGreen - $nRed) / ($nBlue - $nRed))))
Case ($nBlue >= $nRed) And ($nRed >= $nGreen) ; Blue Highest, Green Lowest
$nHue = (60 * (4 + (($nRed - $nGreen) / ($nBlue - $nGreen))))
EndSelect
; Determine Saturation
$nSaturation = ($nMaxRGB = 0) ? (0) : (($nMaxRGB - $nMinRGB) / $nMaxRGB)
$nHue = ($nHue > 0) ? (Round($nHue)) : (0)
$nSaturation = Round(($nSaturation * 100))
$nBrightness = Round(($nBrightness * 100))
ReDim $aiReturn[3]
$aiReturn[0] = $nHue
$aiReturn[1] = $nSaturation
$aiReturn[2] = $nBrightness
Return SetError($__LO_STATUS_SUCCESS, 3, $aiReturn)
Case IsInt($iCMYK) ; Long to CMYK
$nRed = (Mod(($iCMYK / 65536), 256))
$nGreen = (Mod(($iCMYK / 256), 256))
$nBlue = (Mod($iCMYK, 256))
$nRed = Round(($nRed / 255), 3)
$nGreen = Round(($nGreen / 255), 3)
$nBlue = Round(($nBlue / 255), 3)
; get Max RGB Value
$nResult = ($nRed > $nGreen) ? ($nRed) : ($nGreen)
$nMaxRGB = ($nResult > $nBlue) ? ($nResult) : ($nBlue)
$nBlack = (1 - $nMaxRGB)
$nCyan = ((1 - $nRed - $nBlack) / (1 - $nBlack))
$nMagenta = ((1 - $nGreen - $nBlack) / (1 - $nBlack))
$nYellow = ((1 - $nBlue - $nBlack) / (1 - $nBlack))
$nCyan = Round(($nCyan * 100))
$nMagenta = Round(($nMagenta * 100))
$nYellow = Round(($nYellow * 100))
$nBlack = Round(($nBlack * 100))
ReDim $aiReturn[4]
$aiReturn[0] = $nCyan
$aiReturn[1] = $nMagenta
$aiReturn[2] = $nYellow
$aiReturn[3] = $nBlack
Return SetError($__LO_STATUS_SUCCESS, 4, $aiReturn)
Case Else
Return SetError($__LO_STATUS_INPUT_ERROR, 2, 0) ; no parameters set to an integer
EndSelect
EndFunc ;==>_LO_ConvertColorFromLong
; #FUNCTION# ====================================================================================================================
; Name ..........: _LO_ConvertColorToLong
; Description ...: Convert Hex, RGB, HSB or CMYK to a RGB Color Integer.
; Syntax ........: _LO_ConvertColorToLong([$vVal1 = Null[, $vVal2 = Null[, $vVal3 = Null[, $vVal4 = Null]]]])
; Parameters ....: $vVal1 - [optional] a variant value. Default is Null. See remarks.
; $vVal2 - [optional] a variant value. Default is Null. See remarks.
; $vVal3 - [optional] a variant value. Default is Null. See remarks.
; $vVal4 - [optional] a variant value. Default is Null. See remarks.
; Return values .: Success: Integer.
; Failure: 0 and sets the @Error and @Extended flags to non-zero.
; --Input Errors--
; @Error 1 @Extended 1 Return 0 = No parameters set.
; @Error 1 @Extended 2 Return 0 = One parameter called, but not in String format(Hex).
; @Error 1 @Extended 3 Return 0 = Hex parameter contains non Hex characters.
; @Error 1 @Extended 4 Return 0 = Hex parameter not 6 characters long.
; @Error 1 @Extended 5 Return 0 = Hue parameter contains more than just digits.
; @Error 1 @Extended 6 Return 0 = Saturation parameter contains more than just digits.
; @Error 1 @Extended 7 Return 0 = Brightness parameter contains more than just digits.
; @Error 1 @Extended 8 Return 0 = Three parameters called but not all Integers (RGB) and not all Strings (HSB).
; @Error 1 @Extended 9 Return 0 = Four parameters called but not all Integers(CMYK).
; @Error 1 @Extended 10 Return 0 = Too many or too few parameters called.
; --Success--
; @Error 0 @Extended 1 Return Integer = RGB Color Integer converted from Hexadecimal.
; @Error 0 @Extended 2 Return Integer = RGB Color Integer converted from Red, Green, Blue, (RGB).
; @Error 0 @Extended 3 Return Integer = RGB Color Integer converted from (H)ue, (S)aturation, (B)rightness,
; @Error 0 @Extended 4 Return Integer = RGB Color Integer converted from (C)yan, (M)agenta, (Y)ellow, Blac(k)
; Author ........: donnyh13
; Modified ......:
; Remarks .......: To Convert a Hex(adecimal) color code, call the Hex code in $vVal1 in String Format.
; To convert a R(ed) G(reen) B(lue color, call R value in $vVal1 as an Integer, G in $vVal2 as an Integer, and B in $vVal3 as an Integer.
; To convert a H(ue) S(aturation) B(rightness) color, call H in $vVal1 as a String, S in $vVal2 as a String, and B in $vVal3 as a string.
; To convert C(yan) M(agenta) Y(ellow) Blac(k) call C in $vVal1 as an Integer, M in $vVal2 as an Integer, Y in $vVal3 as an Integer, and K in $vVal4 as an Integer.
; The Hexadecimal figure entered cannot contain the usual "0x", as LibreOffice does not implement it in its numbering system.
; Related .......: _LO_ConvertColorFromLong
; Link ..........:
; Example .......: Yes
; ===============================================================================================================================
Func _LO_ConvertColorToLong($vVal1 = Null, $vVal2 = Null, $vVal3 = Null, $vVal4 = Null) ; RGB = Int, CMYK = Int, HSB = String, Hex = String.
Local Const $__STR_STRIPALL = 8
Local $iRed, $iGreen, $iBlue, $iLong, $iHue, $iSaturation, $iBrightness
Local $dHex
Local $nMaxRGB, $nMinRGB, $nChroma, $nHuePre, $nCyan, $nMagenta, $nYellow, $nBlack
If (@NumParams = 0) Then Return SetError($__LO_STATUS_INPUT_ERROR, 1, 0)
Switch @NumParams
Case 1 ; Hex
If Not IsString($vVal1) Then Return SetError($__LO_STATUS_INPUT_ERROR, 2, 0) ; not a string
$vVal1 = StringStripWS($vVal1, $__STR_STRIPALL)
$dHex = $vVal1
; From Hex to RGB
If (StringLen($dHex) = 6) Then
If StringRegExp($dHex, "[^0-9a-fA-F]") Then Return SetError($__LO_STATUS_INPUT_ERROR, 3, 0) ; $dHex contains non Hex characters.
$iRed = BitAND(BitShift("0x" & $dHex, 16), 0xFF)
$iGreen = BitAND(BitShift("0x" & $dHex, 8), 0xFF)
$iBlue = BitAND("0x" & $dHex, 0xFF)
$iLong = BitShift($iRed, -16) + BitShift($iGreen, -8) + $iBlue
Return SetError($__LO_STATUS_SUCCESS, 1, $iLong) ; Long from Hex
Else
Return SetError($__LO_STATUS_INPUT_ERROR, 4, 0) ; Wrong length of string.
EndIf
Case 3 ; RGB and HSB; HSB is all strings, RGB all Integers.
If (IsInt($vVal1) And IsInt($vVal2) And IsInt($vVal3)) Then ; RGB
$iRed = $vVal1
$iGreen = $vVal2
$iBlue = $vVal3
; RGB to Long
$iLong = BitShift($iRed, -16) + BitShift($iGreen, -8) + $iBlue
Return SetError($__LO_STATUS_SUCCESS, 2, $iLong) ; Long from RGB
ElseIf IsString($vVal1) And IsString($vVal2) And IsString($vVal3) Then ; Hue Saturation and Brightness (HSB)
; HSB to RGB
$vVal1 = StringStripWS($vVal1, $__STR_STRIPALL)
$vVal2 = StringStripWS($vVal2, $__STR_STRIPALL)
$vVal3 = StringStripWS($vVal3, $__STR_STRIPALL) ; Strip WS so I can check string length in HSB conversion.
$iHue = Number($vVal1)
If (StringLen($vVal1)) <> (StringLen($iHue)) Then Return SetError($__LO_STATUS_INPUT_ERROR, 5, 0) ; String contained more than just digits
$iSaturation = Number($vVal2)
If (StringLen($vVal2)) <> (StringLen($iSaturation)) Then Return SetError($__LO_STATUS_INPUT_ERROR, 6, 0) ; String contained more than just digits
$iBrightness = Number($vVal3)
If (StringLen($vVal3)) <> (StringLen($iBrightness)) Then Return SetError($__LO_STATUS_INPUT_ERROR, 7, 0) ; String contained more than just digits
$nMaxRGB = ($iBrightness / 100)
$nChroma = (($iSaturation / 100) * ($iBrightness / 100))
$nMinRGB = ($nMaxRGB - $nChroma)
$nHuePre = ($iHue >= 300) ? (($iHue - 360) / 60) : ($iHue / 60)
Switch $nHuePre
Case (-1) To 1.0
$iRed = $nMaxRGB
If $nHuePre < 0 Then
$iGreen = $nMinRGB
$iBlue = ($iGreen - $nHuePre * $nChroma)
Else
$iBlue = $nMinRGB
$iGreen = ($iBlue + $nHuePre * $nChroma)
EndIf
Case 1.1 To 3.0
$iGreen = $nMaxRGB
If (($nHuePre - 2) < 0) Then
$iBlue = $nMinRGB
$iRed = ($iBlue - ($nHuePre - 2) * $nChroma)
Else
$iRed = $nMinRGB
$iBlue = ($iRed + ($nHuePre - 2) * $nChroma)
EndIf
Case 3.1 To 5
$iBlue = $nMaxRGB
If (($nHuePre - 4) < 0) Then
$iRed = $nMinRGB
$iGreen = ($iRed - ($nHuePre - 4) * $nChroma)
Else
$iGreen = $nMinRGB
$iRed = ($iGreen + ($nHuePre - 4) * $nChroma)
EndIf
EndSwitch
$iRed = Round(($iRed * 255))
$iGreen = Round(($iGreen * 255))
$iBlue = Round(($iBlue * 255))
$iLong = BitShift($iRed, -16) + BitShift($iGreen, -8) + $iBlue
Return SetError($__LO_STATUS_SUCCESS, 3, $iLong) ; Return Long from HSB
Else
Return SetError($__LO_STATUS_INPUT_ERROR, 8, 0) ; Wrong parameters
EndIf
Case 4 ; CMYK
If Not (IsInt($vVal1) And IsInt($vVal2) And IsInt($vVal3) And IsInt($vVal4)) Then Return SetError($__LO_STATUS_INPUT_ERROR, 9, 0) ; CMYK not integers.
; CMYK to RGB
$nCyan = ($vVal1 / 100)
$nMagenta = ($vVal2 / 100)
$nYellow = ($vVal3 / 100)
$nBlack = ($vVal4 / 100)
$iRed = Round((255 * (1 - $nBlack) * (1 - $nCyan)))
$iGreen = Round((255 * (1 - $nBlack) * (1 - $nMagenta)))
$iBlue = Round((255 * (1 - $nBlack) * (1 - $nYellow)))
$iLong = BitShift($iRed, -16) + BitShift($iGreen, -8) + $iBlue
Return SetError($__LO_STATUS_SUCCESS, 4, $iLong) ; Long from CMYK
Case Else
Return SetError($__LO_STATUS_INPUT_ERROR, 10, 0) ; wrong number of Parameters
EndSwitch
EndFunc ;==>_LO_ConvertColorToLong
; #FUNCTION# ====================================================================================================================
; Name ..........: _LO_DocConnect
; Description ...: Connect to an already opened instance of LibreOffice.
; Syntax ........: _LO_DocConnect([$iMode = $LO_DOC_CONNECT_MODE_CURRENT[, $sSearch = ""[, $bCaseless = False]]])
; Parameters ....: $iMode - [optional] an integer value (0-4). Default is $LO_DOC_CONNECT_MODE_CURRENT. The Connect mode. See Constants, $LO_DOC_CONNECT_MODE_* as defined in LibreOffice_Constants.au3.
; $sSearch - [optional] a string value. Default is "". The Name, Title or Path of the Document to search for. See remarks.
; $bCaseless - [optional] a boolean value. Default is False. If True, searches are caseless when using $LO_DOC_CONNECT_MODE_SEARCH_* flags.
; Return values .: Success: Object or Array.
; Failure: 0 and sets the @Error and @Extended flags to non-zero.
; --Input Errors--
; @Error 1 @Extended 1 Return 0 = $iMode not an Integer, less than 0 or greater than 4. See Constants, $LO_DOC_CONNECT_MODE_* as defined in LibreOffice_Constants.au3.
; @Error 1 @Extended 2 Return 0 = $sSearch not a String.
; @Error 1 @Extended 3 Return 0 = $bCaseless not a Boolean.
; --Initialization Errors--
; @Error 2 @Extended 1 Return 0 = Error creating ServiceManager object.
; @Error 2 @Extended 2 Return 0 = Error creating Desktop object.
; @Error 2 @Extended 3 Return 0 = Error creating enumeration of open documents.
; --Processing Errors--
; @Error 3 @Extended 1 Return 0 = No open LibreOffice documents.
; @Error 3 @Extended 2 Return 0 = Failed to retrieve Document Object.
; @Error 3 @Extended 3 Return 0 = Failed to identify Document type.
; @Error 3 @Extended 4 Return 0 = Error converting path to LibreOffice URL.
; @Error 3 @Extended 5 Return 0 = No matches found.
; --Success--
; @Error 0 @Extended ? Return Object = Success, The Object for the current, or last active document is returned. @Extended set to Document type Constant as an Integer. See Constants, $LO_DOC_TYPE_* as defined in LibreOffice_Constants.au3.
; @Error 0 @Extended ? Return Object = Success, The Object for the found Document with matching Name, Title or Path. @Extended set to Document type Constant as an Integer. See Constants, $LO_DOC_TYPE_* as defined in LibreOffice_Constants.au3.
; @Error 0 @Extended ? Return Array = Success, An Array of all open LibreOffice Documents. @Extended is set to number of results. See remarks.
; Author ........: donnyh13
; Modified ......:
; Remarks .......: The value used for $sSearch depends on the flag called in $iMode. It is ignored except for the $LO_DOC_CONNECT_MODE_SEARCH_* flags.
; If $iMode is called with $LO_DOC_CONNECT_MODE_SEARCH_TITLE, $sSearch must be the full Title with Office and Component name; e.g: "Test.odt — LibreOffice Writer". This will be the same Title AutoIt would match or return from functions like WinGetTitle.
; If $iMode is called with $LO_DOC_CONNECT_MODE_SEARCH_NAME, $sSearch must be the Document's full name, without the extension; e.g: "Test".
; If $iMode is called with $LO_DOC_CONNECT_MODE_SEARCH_NAME_WITH_EXT, $sSearch must be the Document's name, with the extension; e.g: "Test.odt". If the Document hasn't been saved, just the name will work, e.g., "Untitled 1".
; If $iMode is called with $LO_DOC_CONNECT_MODE_SEARCH_PATH, $sSearch must be the full Path of the document (Name and extension included); e.g: "C:\file\Test.odt."
; The Connect All option returns an array with two columns per result. ($aArray[0][2]), each result is stored in a separate row.
; -Row 1, Column 0 contains the Object for that document. e.g. $aArray[0][0] = $oDoc
; -Row 1, Column 1 contains the Document's Type as an Integer. See Constants, $LO_DOC_TYPE_* as defined in LibreOffice_Constants.au3. e.g. $aArray[0][1] = $LO_DOC_TYPE_CALC
; -Row 2, Column 0 contains the Object for the next document. e.g. $aArray[1][0] = $oDoc2. And so on.
; Related .......:
; Link ..........:
; Example .......: Yes
; ===============================================================================================================================
Func _LO_DocConnect($iMode = $LO_DOC_CONNECT_MODE_CURRENT, $sSearch = "", $bCaseless = False)
Local $oCOM_ErrorHandler = ObjEvent("AutoIt.Error", __LO_InternalComErrorHandler)
#forceref $oCOM_ErrorHandler
Local $iCount = 0, $iDocType
Local $aoConnectAll[0][2]
Local $sCaseless = ""
Local $oEnumDoc, $oDoc, $oServiceManager, $oDesktop
If Not __LO_IntIsBetween($iMode, $LO_DOC_CONNECT_MODE_ALL, $LO_DOC_CONNECT_MODE_SEARCH_PATH) Then Return SetError($__LO_STATUS_INPUT_ERROR, 1, 0)
If Not IsString($sSearch) Then Return SetError($__LO_STATUS_INPUT_ERROR, 2, 0)
If Not IsBool($bCaseless) Then Return SetError($__LO_STATUS_INPUT_ERROR, 3, 0)
$oServiceManager = __LO_ServiceManager()
If Not IsObj($oServiceManager) Then Return SetError($__LO_STATUS_INIT_ERROR, 1, 0)
$oDesktop = $oServiceManager.createInstance("com.sun.star.frame.Desktop")
If Not IsObj($oDesktop) Then Return SetError($__LO_STATUS_INIT_ERROR, 2, 0)
If Not $oDesktop.getComponents.hasElements() Then Return SetError($__LO_STATUS_PROCESSING_ERROR, 1, 0) ; no L.O open
Switch $iMode
Case $LO_DOC_CONNECT_MODE_ALL
$oEnumDoc = $oDesktop.getComponents.createEnumeration()
If Not IsObj($oEnumDoc) Then Return SetError($__LO_STATUS_INIT_ERROR, 3, 0)
While $oEnumDoc.hasMoreElements()
$oDoc = $oEnumDoc.nextElement()
If Not IsObj($oDoc) Then Return SetError($__LO_STATUS_PROCESSING_ERROR, 2, 0)
If (UBound($aoConnectAll) <= $iCount) Then ReDim $aoConnectAll[$iCount + 1][2]
$aoConnectAll[$iCount][0] = $oDoc
$aoConnectAll[$iCount][1] = _LO_DocGetType($oDoc)
$iCount += 1
Sleep((IsInt($iCount / $__LOCONST_SLEEP_DIV) ? (10) : (0)))
WEnd
Return SetError($__LO_STATUS_SUCCESS, $iCount, $aoConnectAll)
Case $LO_DOC_CONNECT_MODE_CURRENT
$oDoc = $oDesktop.currentComponent()
If Not IsObj($oDoc) Then Return SetError($__LO_STATUS_PROCESSING_ERROR, 2, 0)
$iDocType = _LO_DocGetType($oDoc)
If @error Then Return SetError($__LO_STATUS_PROCESSING_ERROR, 3, 0) ; Failed to identify Doc type.
Return SetError($__LO_STATUS_SUCCESS, $iDocType, $oDoc)
Case $LO_DOC_CONNECT_MODE_SEARCH_TITLE, $LO_DOC_CONNECT_MODE_SEARCH_NAME, $LO_DOC_CONNECT_MODE_SEARCH_NAME_WITH_EXT, $LO_DOC_CONNECT_MODE_SEARCH_PATH
$sSearch = StringRegExpReplace($sSearch, "(^\s*|\s*$)", "") ; Strip leading and trailing spaces
If $bCaseless Then $sCaseless = "(?i)"
If ($iMode = $LO_DOC_CONNECT_MODE_SEARCH_PATH) Then
$sSearch = _LO_PathConvert($sSearch, $LO_PATHCONV_OFFICE_RETURN) ; Convert to L.O File path.
If @error Then Return SetError($__LO_STATUS_PROCESSING_ERROR, 4, 0)
EndIf
$oEnumDoc = $oDesktop.getComponents.createEnumeration()
If Not IsObj($oEnumDoc) Then Return SetError($__LO_STATUS_INIT_ERROR, 3, 0)
While $oEnumDoc.hasMoreElements()
$oDoc = $oEnumDoc.nextElement()
If Not IsObj($oDoc) Then Return SetError($__LO_STATUS_PROCESSING_ERROR, 2, 0)
Switch $iMode
Case $LO_DOC_CONNECT_MODE_SEARCH_TITLE
; First make sure Current Controller is available (It wont be if Document is opened Hidden, in some Components.).
If IsObj($oDoc.CurrentController()) And StringRegExp($oDoc.CurrentController.Frame.Title(), $sCaseless & "\Q" & $sSearch & "\E") Then
$iDocType = _LO_DocGetType($oDoc)
If @error Then Return SetError($__LO_STATUS_PROCESSING_ERROR, 3, 0) ; Failed to identify Doc type.
Return SetError($__LO_STATUS_SUCCESS, $iDocType, $oDoc)
EndIf
Case $LO_DOC_CONNECT_MODE_SEARCH_NAME
; Add spaces after name in case user put some in the Document name.
; Add additional capture for Extension to just match the name the user put in, else force match at end of String for unsaved Documents.
If StringRegExp($oDoc.Title(), $sCaseless & "\Q" & $sSearch & "\E\s*(\.\w+)?$") Then
$iDocType = _LO_DocGetType($oDoc)
If @error Then Return SetError($__LO_STATUS_PROCESSING_ERROR, 3, 0) ; Failed to identify Doc type.
Return SetError($__LO_STATUS_SUCCESS, $iDocType, $oDoc)
EndIf
Case $LO_DOC_CONNECT_MODE_SEARCH_NAME_WITH_EXT
If StringRegExp($oDoc.Title(), $sCaseless & "\Q" & $sSearch & "\E") Then
$iDocType = _LO_DocGetType($oDoc)
If @error Then Return SetError($__LO_STATUS_PROCESSING_ERROR, 3, 0) ; Failed to identify Doc type.
Return SetError($__LO_STATUS_SUCCESS, $iDocType, $oDoc)
EndIf
Case $LO_DOC_CONNECT_MODE_SEARCH_PATH
If StringRegExp($oDoc.getURL(), $sCaseless & "\Q" & $sSearch & "\E") Then
$iDocType = _LO_DocGetType($oDoc)
If @error Then Return SetError($__LO_STATUS_PROCESSING_ERROR, 3, 0) ; Failed to identify Doc type.
Return SetError($__LO_STATUS_SUCCESS, $iDocType, $oDoc)
EndIf
EndSwitch
WEnd
EndSwitch
Return SetError($__LO_STATUS_PROCESSING_ERROR, 5, 0) ; No matches
EndFunc ;==>_LO_DocConnect
; #FUNCTION# ====================================================================================================================
; Name ..........: _LO_DocGetType
; Description ...: Identify the document's type.
; Syntax ........: _LO_DocGetType(ByRef $oDoc)
; Parameters ....: $oDoc - [in/out] an object. A Document object returned by a previous Document Open, Connect, or Create function.
; Return values .: Success: Integer
; Failure: 0 and sets the @Error and @Extended flags to non-zero.
; --Input Errors--
; @Error 1 @Extended 1 Return 0 = $oDoc not an Object.
; --Processing Errors--
; @Error 3 @Extended 1 Return 0 = Failed to retrieve a Form Cursor.
; @Error 3 @Extended 2 Return 0 = Failed to retrieve Table or Query name.
; @Error 3 @Extended 3 Return 0 = Failed to retrieve Active Connection Object.
; @Error 3 @Extended 4 Return 0 = Failed to retrieve Document Creation Arguments Array.
; --Success--
; @Error 0 @Extended 0 Return Integer = Success. Returning the document's type as an Integer. See Constants, $LO_DOC_TYPE_* as defined in LibreOffice_Constants.au3.
; Author ........: donnyh13
; Modified ......:
; Remarks .......:
; Related .......:
; Link ..........:
; Example .......: Yes
; ===============================================================================================================================
Func _LO_DocGetType(ByRef $oDoc)
Local $oCOM_ErrorHandler = ObjEvent("AutoIt.Error", __LO_InternalComErrorHandler)
#forceref $oCOM_ErrorHandler
Local $iDocType = $LO_DOC_TYPE_UNKNOWN
Local $atArgs
Local $asMatch
Local $oRowSet, $oActiveConn
Local $sName, $sDocumentBaseURL, $sDocTitle = ""
Local Const $__STR_REGEXPARRAYMATCH = 1
Local Const $sBaseServiceName = "com.sun.star.sdb.OfficeDatabaseDocument", _ ; Base
$sBaseQueryDesignServiceName = "com.sun.star.sdb.QueryDesign", _ ; Base Query Document in Design mode.
$sBaseTableDesignServiceName = "com.sun.star.sdb.TableDesign", _ ; Base Table Document in Design mode.
$sBaseReportDesignServiceName = "com.sun.star.report.ReportDefinition", _ ; Base Report Doc in Design mode.
$sBaseSubServiceName = "com.sun.star.sdb.DataSourceBrowser", _ ; Could be a Query or a Table Document in Viewing mode.
$sBasicIDEServiceName = "com.sun.star.script.BasicIDE", _ ; Basic IDE
$sCalcServiceName = "com.sun.star.sheet.SpreadsheetDocument", _ ; Calc or Report (View)
$sDrawServiceName = "com.sun.star.drawing.DrawingDocument", _ ; Draw
$sImpressServiceName = "com.sun.star.presentation.PresentationDocument", _ ; Impress
$sMathServiceName = "com.sun.star.formula.FormulaProperties", _ ; Math
$sWriterWebServiceName = "com.sun.star.text.WebDocument", _ ; Writer Web/HTML
$sTextDocServiceName = "com.sun.star.text.TextDocument" ; Could be a Writer Doc, or Form (View and Design), or Report (View)
If Not IsObj($oDoc) Then Return SetError($__LO_STATUS_INPUT_ERROR, 1, 0)
If $oDoc.supportsService($sBaseServiceName) Then
$iDocType = $LO_DOC_TYPE_BASE
ElseIf $oDoc.supportsService($sBaseQueryDesignServiceName) Then
$iDocType = $LO_DOC_TYPE_BASE_QUERY_DESIGN
ElseIf $oDoc.supportsService($sBaseTableDesignServiceName) Then
$iDocType = $LO_DOC_TYPE_BASE_TABLE_DESIGN
ElseIf $oDoc.supportsService($sBaseReportDesignServiceName) Then
$iDocType = $LO_DOC_TYPE_BASE_REPORT_DESIGN
ElseIf $oDoc.supportsService($sBaseSubServiceName) Then
$oRowSet = $oDoc.FormOperations.Cursor()
If Not IsObj($oRowSet) Then Return SetError($__LO_STATUS_PROCESSING_ERROR, 1, 0)
$sName = $oRowSet.Command()
If Not IsString($sName) Then Return SetError($__LO_STATUS_PROCESSING_ERROR, 2, 0)
$oActiveConn = $oRowSet.ActiveConnection()
If Not IsObj($oActiveConn) Then Return SetError($__LO_STATUS_PROCESSING_ERROR, 3, 0)
If $oActiveConn.Queries.hasByName($sName) Then
$iDocType = $LO_DOC_TYPE_BASE_QUERY_VIEW
ElseIf $oActiveConn.Tables.hasByName($sName) Then
$iDocType = $LO_DOC_TYPE_BASE_TABLE_VIEW
EndIf
ElseIf $oDoc.supportsService($sTextDocServiceName) Then
; For Form Doc, check if it has a parent, then check if parent is a Base Doc.
; Form documents have DocumentBaseURL also, URL matches Base file URL.
; If Form is read-Only, then View mode, else Design.
If IsObj($oDoc.Parent()) And $oDoc.Parent.supportsService($sBaseServiceName) Then ; A Form, View or Design.
$atArgs = $oDoc.Args()
If Not IsArray($atArgs) Then Return SetError($__LO_STATUS_PROCESSING_ERROR, 4, 0)
For $i = 0 To UBound($atArgs) - 1
If ($atArgs[$i].Name() = "DocumentBaseURL") Then
$sDocumentBaseURL = $atArgs[$i].Value()
ExitLoop
EndIf
Sleep((IsInt($i / $__LOCONST_SLEEP_DIV) ? (10) : (0)))
Next
If IsString($sDocumentBaseURL) And ($oDoc.Parent.URL() = $sDocumentBaseURL) Then
If $oDoc.isReadOnly() Then ; Form in View mode.
$iDocType = $LO_DOC_TYPE_BASE_FORM_VIEW
Else ; Form in Design mode.
$iDocType = $LO_DOC_TYPE_BASE_FORM_DESIGN
EndIf
EndIf
ElseIf $oDoc.isReadOnly() Then ; Could be a Writer Doc or Report in View mode, as both have no parent.
$atArgs = $oDoc.Args()
If Not IsArray($atArgs) Then Return SetError($__LO_STATUS_PROCESSING_ERROR, 4, 0)
For $i = 0 To UBound($atArgs) - 1
If ($atArgs[$i].Name() = "DocumentBaseURL") Then
$sDocumentBaseURL = $atArgs[$i].Value()
ExitLoop
EndIf
Sleep((IsInt($i / $__LOCONST_SLEEP_DIV) ? (10) : (0)))
Next
If IsString($sDocumentBaseURL) Then ; Probably a Report in View mode.
; Title: "QryAutoIt.docx (read-only)" (Need to cut it at the space.)
$asMatch = StringRegExp($oDoc.Title(), "^(.+\.\w+)", $__STR_REGEXPARRAYMATCH)
If Not @error Then $sDocTitle = $asMatch[0]
; Report doc in view mode has URL: file:///C:/Users/Owner/AppData/Local/Temp/lu1376bt3zd.tmp/QryAutoIt.docx
; Can search for .tmp/ + Report name.
If StringRegExp($sDocumentBaseURL, "\/\w+\.(?i)tmp\/\Q" & $sDocTitle & "\E") Then $iDocType = $LO_DOC_TYPE_BASE_REPORT_VIEW
Else ; Assuming, and most probably, a Writer Document.
$iDocType = $LO_DOC_TYPE_WRITER
EndIf
Else ; Not Read Only, most likely a Writer Doc.
$iDocType = $LO_DOC_TYPE_WRITER
EndIf
ElseIf $oDoc.supportsService($sBasicIDEServiceName) Then
$iDocType = $LO_DOC_TYPE_BASIC_IDE
ElseIf $oDoc.supportsService($sCalcServiceName) Then
If $oDoc.isReadOnly() Then ; Could be a Calc Doc or Report in View mode.
$atArgs = $oDoc.Args()
If Not IsArray($atArgs) Then Return SetError($__LO_STATUS_PROCESSING_ERROR, 4, 0)
For $i = 0 To UBound($atArgs) - 1
If ($atArgs[$i].Name() = "DocumentBaseURL") Then
$sDocumentBaseURL = $atArgs[$i].Value()
ExitLoop
EndIf
Sleep((IsInt($i / $__LOCONST_SLEEP_DIV) ? (10) : (0)))
Next
If IsString($sDocumentBaseURL) Then ; Probably a Report in View mode.
; Title: "QryAutoIt1.ods (read-only)" (Need to cut it at the space.)
$asMatch = StringRegExp($oDoc.Title(), "^(.+\.\w+)", $__STR_REGEXPARRAYMATCH)
If Not @error Then $sDocTitle = $asMatch[0]
; Report doc in view mode has URL: file:///C:/Users/Owner/AppData/Local/Temp/lu20921b6g.tmp/QryAutoIt1.ods
; Can search for .tmp/ + Report name.
If StringRegExp($sDocumentBaseURL, "\/\w+\.(?i)tmp\/\Q" & $sDocTitle & "\E") Then $iDocType = $LO_DOC_TYPE_BASE_REPORT_VIEW
Else ; Assuming, and most probably, a Calc Document.
$iDocType = $LO_DOC_TYPE_CALC
EndIf
Else ; Not Read Only, most probably a Calc Document.
$iDocType = $LO_DOC_TYPE_CALC
EndIf
ElseIf $oDoc.supportsService($sImpressServiceName) Then ; ALWAYS need to check for Impress before Draw, as Draw has all same services as Impress.
$iDocType = $LO_DOC_TYPE_IMPRESS
ElseIf $oDoc.supportsService($sDrawServiceName) Then
$iDocType = $LO_DOC_TYPE_DRAW
ElseIf $oDoc.supportsService($sMathServiceName) Then
$iDocType = $LO_DOC_TYPE_MATH
ElseIf $oDoc.supportsService($sWriterWebServiceName) Then
$iDocType = $LO_DOC_TYPE_WRITER_WEB
EndIf
Return SetError($__LO_STATUS_SUCCESS, 0, $iDocType)
EndFunc ;==>_LO_DocGetType
; #FUNCTION# ====================================================================================================================
; Name ..........: _LO_GradientMulticolorAdd
; Description ...: Add a ColorStop to a Gradient ColorStop Array.
; Syntax ........: _LO_GradientMulticolorAdd(ByRef $avColorStops, $iIndex, $nStopOffset, $iColor)
; Parameters ....: $avColorStops - [in/out] an array of variants. A two column array of ColorStops. Array will be directly modified.
; $iIndex - an integer value. The array index to insert the color stop. 0 Based. Call the last element index plus 1 to insert at the end.
; $nStopOffset - a general number value (0-1.0). The ColorStop offset value.
; $iColor - an integer value (0-16777215). The ColorStop color, as a RGB Color Integer. Can be a custom value, or one of the constants, $LO_COLOR_* as defined in LibreOffice_Constants.au3.
; Return values .: Success: 1
; Failure: 0 and sets the @Error and @Extended flags to non-zero.
; --Input Errors--
; @Error 1 @Extended 1 Return 0 = $avColorStops not an Array.
; @Error 1 @Extended 2 Return 0 = $avColorStops does not contain two columns.
; @Error 1 @Extended 3 Return 0 = $iIndex not an Integer, less than 0 or greater than last element plus 1.
; @Error 1 @Extended 4 Return 0 = $nStopOffset not a number, less than 0 or greater than 1.0.
; @Error 1 @Extended 5 Return 0 = $iColor not an Integer, less than 0 or greater than 16777215.
; --Success--
; @Error 0 @Extended 0 Return 1 = Success. ColorStop successfully added to array.
; Author ........: donnyh13
; Modified ......:
; Remarks .......:
; Related .......:
; Link ..........:
; Example .......: Yes
; ===============================================================================================================================
Func _LO_GradientMulticolorAdd(ByRef $avColorStops, $iIndex, $nStopOffset, $iColor)
Local $oCOM_ErrorHandler = ObjEvent("AutoIt.Error", __LO_InternalComErrorHandler)
#forceref $oCOM_ErrorHandler
Local Const $__UBOUND_COLUMNS = 2
If Not IsArray($avColorStops) Then Return SetError($__LO_STATUS_INPUT_ERROR, 1, 0)
If (UBound($avColorStops, $__UBOUND_COLUMNS) <> 2) Then Return SetError($__LO_STATUS_INPUT_ERROR, 2, 0)
If Not __LO_IntIsBetween($iIndex, 0, UBound($avColorStops)) Then Return SetError($__LO_STATUS_INPUT_ERROR, 3, 0)
If Not __LO_NumIsBetween($nStopOffset, 0, 1.0) Then Return SetError($__LO_STATUS_INPUT_ERROR, 4, 0)
If Not __LO_IntIsBetween($iColor, $LO_COLOR_BLACK, $LO_COLOR_WHITE) Then Return SetError($__LO_STATUS_INPUT_ERROR, 5, 0)
ReDim $avColorStops[UBound($avColorStops) + 1][2]
For $iToWrite = (UBound($avColorStops) - 1) To 0 Step -1
If $iToWrite = $iIndex Then
$avColorStops[$iToWrite][0] = $nStopOffset
$avColorStops[$iToWrite][1] = $iColor
ExitLoop
Else
$avColorStops[$iToWrite][0] = $avColorStops[$iToWrite - 1][0]
$avColorStops[$iToWrite][1] = $avColorStops[$iToWrite - 1][1]
EndIf
Sleep((IsInt($iToWrite / $__LOCONST_SLEEP_DIV) ? (10) : (0)))
Next
Return SetError($__LO_STATUS_SUCCESS, 0, 1)
EndFunc ;==>_LO_GradientMulticolorAdd
; #FUNCTION# ====================================================================================================================
; Name ..........: _LO_GradientMulticolorDelete
; Description ...: Delete a ColorStop from a Gradient ColorStop Array.
; Syntax ........: _LO_GradientMulticolorDelete(ByRef $avColorStops, $iIndex)
; Parameters ....: $avColorStops - [in/out] an array of variants. A two column array of ColorStops. Array will be directly modified.
; $iIndex - an integer value. The array index to delete. 0 Based.
; Return values .: Success: 1
; Failure: 0 and sets the @Error and @Extended flags to non-zero.
; --Input Errors--
; @Error 1 @Extended 1 Return 0 = $avColorStops not an Array.
; @Error 1 @Extended 2 Return 0 = $avColorStops does not contain two columns.
; @Error 1 @Extended 3 Return 0 = $iIndex not an Integer, less than 0 or greater than last element plus 1.
; --Success--
; @Error 0 @Extended 0 Return 1 = Success. ColorStop successfully removed from array.
; Author ........: donnyh13
; Modified ......:
; Remarks .......:
; Related .......:
; Link ..........:
; Example .......: Yes
; ===============================================================================================================================
Func _LO_GradientMulticolorDelete(ByRef $avColorStops, $iIndex)
Local $oCOM_ErrorHandler = ObjEvent("AutoIt.Error", __LO_InternalComErrorHandler)
#forceref $oCOM_ErrorHandler
Local Const $__UBOUND_COLUMNS = 2
Local $iToRead = 0
If Not IsArray($avColorStops) Then Return SetError($__LO_STATUS_INPUT_ERROR, 1, 0)
If (UBound($avColorStops, $__UBOUND_COLUMNS) <> 2) Then Return SetError($__LO_STATUS_INPUT_ERROR, 2, 0)
If Not __LO_IntIsBetween($iIndex, 0, UBound($avColorStops) - 1) Then Return SetError($__LO_STATUS_INPUT_ERROR, 3, 0)
For $iToWrite = 0 To UBound($avColorStops) - 2
If $iToWrite = $iIndex Then $iToRead += 1
$avColorStops[$iToWrite][0] = $avColorStops[$iToWrite + $iToRead][0]
$avColorStops[$iToWrite][1] = $avColorStops[$iToWrite + $iToRead][1]
Sleep((IsInt($iToWrite / $__LOCONST_SLEEP_DIV) ? (10) : (0)))
Next
ReDim $avColorStops[UBound($avColorStops) - 1][2]
Return SetError($__LO_STATUS_SUCCESS, 0, 1)
EndFunc ;==>_LO_GradientMulticolorDelete
; #FUNCTION# ====================================================================================================================
; Name ..........: _LO_GradientMulticolorModify
; Description ...: Modify a ColorStop in a Gradient ColorStop Array.
; Syntax ........: _LO_GradientMulticolorModify(ByRef $avColorStops, $iIndex, $nStopOffset, $iColor)
; Parameters ....: $avColorStops - [in/out] an array of variants. A two column array of ColorStops. Array will be directly modified.
; $iIndex - an integer value. The array index to modify. 0 Based.
; $nStopOffset - a general number value (0-1.0). The ColorStop offset value.
; $iColor - an integer value (0-16777215). The ColorStop color, as a RGB Color Integer. Can be a custom value, or one of the constants, $LO_COLOR_* as defined in LibreOffice_Constants.au3.
; Return values .: Success: 1
; Failure: 0 and sets the @Error and @Extended flags to non-zero.
; --Input Errors--
; @Error 1 @Extended 1 Return 0 = $avColorStops not an Array.
; @Error 1 @Extended 2 Return 0 = $avColorStops does not contain two columns.
; @Error 1 @Extended 3 Return 0 = $iIndex not an Integer, less than 0 or greater than last element.
; @Error 1 @Extended 4 Return 0 = $nStopOffset not a number, less than 0 or greater than 1.0.
; @Error 1 @Extended 5 Return 0 = $iColor not an Integer, less than 0 or greater than 16777215.
; --Success--
; @Error 0 @Extended 0 Return 1 = Success. ColorStop successfully modified.
; Author ........: donnyh13
; Modified ......:
; Remarks .......:
; Related .......:
; Link ..........:
; Example .......: Yes
; ===============================================================================================================================
Func _LO_GradientMulticolorModify(ByRef $avColorStops, $iIndex, $nStopOffset, $iColor)
Local $oCOM_ErrorHandler = ObjEvent("AutoIt.Error", __LO_InternalComErrorHandler)
#forceref $oCOM_ErrorHandler
Local Const $__UBOUND_COLUMNS = 2
If Not IsArray($avColorStops) Then Return SetError($__LO_STATUS_INPUT_ERROR, 1, 0)
If (UBound($avColorStops, $__UBOUND_COLUMNS) <> 2) Then Return SetError($__LO_STATUS_INPUT_ERROR, 2, 0)
If Not __LO_IntIsBetween($iIndex, 0, UBound($avColorStops) - 1) Then Return SetError($__LO_STATUS_INPUT_ERROR, 3, 0)
If Not __LO_NumIsBetween($nStopOffset, 0, 1.0) Then Return SetError($__LO_STATUS_INPUT_ERROR, 4, 0)
If Not __LO_IntIsBetween($iColor, $LO_COLOR_BLACK, $LO_COLOR_WHITE) Then Return SetError($__LO_STATUS_INPUT_ERROR, 5, 0)
For $iToWrite = 0 To UBound($avColorStops) - 1
If $iToWrite = $iIndex Then
$avColorStops[$iToWrite][0] = $nStopOffset
$avColorStops[$iToWrite][1] = $iColor
ExitLoop
EndIf
Sleep((IsInt($iToWrite / $__LOCONST_SLEEP_DIV) ? (10) : (0)))
Next
Return SetError($__LO_STATUS_SUCCESS, 0, 1)
EndFunc ;==>_LO_GradientMulticolorModify
; #FUNCTION# ====================================================================================================================
; Name ..........: _LO_InitializePortable
; Description ...: Setup Portable LibreOffice (Or Open Office) for use in this UDF. See remarks.
; Syntax ........: _LO_InitializePortable($sOfficePortablePath)
; Parameters ....: $sOfficePortablePath - a string value. The Path to the Portable LibreOffice/OpenOffice folder. See remarks.
; Return values .: Success: 1
; Failure: 0 and sets the @Error and @Extended flags to non-zero.
; --Input Errors--
; @Error 1 @Extended 1 Return 0 = $sOfficePortablePath not a String.
; @Error 1 @Extended 2 Return 0 = Folder called in $sOfficePortablePath does not contain the App folder. Perhaps wrong directory?
; @Error 1 @Extended 3 Return 0 = soffice.exe not found in $sOfficePortablePath\App\libreoffice\program\ or $sOfficePortablePath\App\openoffice\program\.
; --Processing Errors--
; @Error 3 @Extended 1 Return 0 = Failed to clear stored Portable LO/OO ServiceManager.
; @Error 3 @Extended 2 Return 0 = Failed to initialize portable LibreOffice ServiceManager.
; @Error 3 @Extended 3 Return 0 = Failed to initialize portable OpenOffice ServiceManager.
; --Success--
; @Error 0 @Extended 0 Return 1 = Success. Portable LibreOffice/OpenOffice ServiceManager successfully created and stored.
; Author ........: donnyh13
; Modified ......:
; Remarks .......: The path called in $sOfficePortablePath should be to the Portable LibreOffice folder containing the shortcuts to each element, and also the "App", "Data" and "Other" folders. e.g. C:\LibreOfficePortablePrevious
; This UDF hasn't been thoroughly tested using portable LibreOffice, but rather the Installed version. Make sure to test all things yourself!
; So far, the following method is the only way I've been able to successfully initialize the portable LibreOffice version from AutoIt. How it works is as follows:
; 1a. If LibreOffice/OpenOffice is already installed on the system, an instance of com.sun.star.ServiceManager is started. __OR__
; 1b. If LibreOffice/OpenOffice is NOT already installed on the system, a handful of temporary registry entries are created in HKEY_CURRENT_USER, to allow an instance of com.sun.star.ServiceManager to be started.
; 2. The Portable LibreOffice/OpenOffice (LO/OO) is started in --headless mode as a listening server, using the flag --accept.
; 3. The ServiceManager created in step 1 is used to create a UNO URL resolver, which is used to obtain a ServiceManager Object from the listening Portable LO/OO.
; 4. The retrieved Portable LO/OO ServiceManager is stored as a static variable for future use. The Portable LO/OO path is also stored as a static variable in case I need to re-create the ServiceManager.
; 5a. The ServiceManager created from the registry is no longer used.
; 5b. The ServiceManager created from the registry is no longer used, and the temporary Registry entries created in HKEY_CURRENT_USER are (hopefully) deleted.
; If the COM error "Binary URP bridge already disposed" is encountered, all instances of soffice.exe or soffice.bin must be closed with TaskManager.
; If running this with an installed version of LibreOffice present the flag SingleAppInstance may need to be set to False in the "LibreOfficePortablePrevious.ini" [or similar name], found at: C:\LibreOfficePortablePrevious\App\AppInfo\Launcher\LibreOfficePortablePrevious.ini.
; Related .......:
; Link ..........:
; Example .......: No
; ===============================================================================================================================
Func _LO_InitializePortable($sOfficePortablePath)
Local $oCOM_ErrorHandler = ObjEvent("AutoIt.Error", __LO_InternalComErrorHandler)
#forceref $oCOM_ErrorHandler
If Not IsString($sOfficePortablePath) Then Return SetError($__LO_STATUS_INPUT_ERROR, 1, 0)
$sOfficePortablePath = StringRegExpReplace($sOfficePortablePath, "^\s+|\s+$", "") ; Strip beginning and ending spaces.
If ($sOfficePortablePath <> "") And Not FileExists($sOfficePortablePath & "\App") Then Return SetError($__LO_STATUS_INPUT_ERROR, 2, 0) ; Make sure we're starting from the right folder.
If ($sOfficePortablePath = "") Then
__LO_SetPortableServiceManager($sOfficePortablePath)
If @error Then Return SetError($__LO_STATUS_PROCESSING_ERROR, 1, 0)
ElseIf FileExists($sOfficePortablePath & "\App\libreoffice\program\soffice.exe") Then ; Check Libre path.
__LO_SetPortableServiceManager($sOfficePortablePath & "\App\libreoffice\program\soffice.exe")
If @error Then Return SetError($__LO_STATUS_PROCESSING_ERROR, 2, 0)
ElseIf FileExists($sOfficePortablePath & "\App\openoffice\program\soffice.exe") Then ; Check OpenOffice path.
__LO_SetPortableServiceManager($sOfficePortablePath & "\App\openoffice\program\soffice.exe")
If @error Then Return SetError($__LO_STATUS_PROCESSING_ERROR, 3, 0)
Else
Return SetError($__LO_STATUS_INPUT_ERROR, 3, 0)
EndIf
Return SetError($__LO_STATUS_SUCCESS, 0, 1)
EndFunc ;==>_LO_InitializePortable
; #FUNCTION# ====================================================================================================================
; Name ..........: _LO_PathConvert
; Description ...: Converts the input path to or from a LibreOffice URL notation path.
; Syntax ........: _LO_PathConvert($sFilePath[, $iReturnMode = $LO_PATHCONV_AUTO_RETURN])
; Parameters ....: $sFilePath - a string value. Full path to convert in String format.
; $iReturnMode - [optional] an integer value (0-2). Default is $__g_iAutoReturn. The type of path format to return. See Constants, $LO_PATHCONV_* as defined in LibreOffice_Constants.au3.
; Return values .: Success: String.
; Failure: 0 and sets the @Error and @Extended flags to non-zero.
; --Input Errors--
; @Error 1 @Extended 1 Return 0 = $sFilePath is not a string
; @Error 1 @Extended 2 Return 0 = $iReturnMode not a Integer, less than 0 or greater than 2. See constants, $LO_PATHCONV_* as defined in LibreOffice_Constants.au3..
; --Success--
; @Error 0 @Extended 1 Return String = Returning converted File Path from LibreOffice URL.
; @Error 0 @Extended 2 Return String = Returning converted path from File Path to LibreOffice URL.
; Author ........: donnyh13
; Modified ......:
; Remarks .......: LibreOffice URL notation is based on the Internet Standard RFC 1738, which means only [0-9],[a-zA-Z] are allowed in paths, most other characters need to be converted into ISO 8859-1 (ISO Latin) such as is found in internet URL's (spaces become %20).