How do I get pixi to read 8 digit hex codes? - vue.js

I'm using Vuetify's color picker which has options for hexa, hsla and rgba. I am using hexa but am willing to use any option that will work.
It seems that Pixi can only understand 6 digits hex codes with 0x in front of it.
I want to be able to use Vuetify's slider and translate the 8 digit hex code to pixi.
Here is what I've tried:
this.sketcher.color = this.color.replace(/\x23/g, '0')
This removes the '#' (ascii 23) from the front and adds 0 in it's place. I read the 0x is for 6 digit hex and 0 is for octal; which I was hoping meant 8 digit hexa codes but it appears that's not correct.
I've also found a workaround to remove the last two digits from the hex value but that removes the transparency.
Is there a way to push over my 8 digit hexa value to pixi in a way that pixi will understand it and display it accordingly?? I'm using it to sketch shapes btw. Thanks!

For a color in string format '#RRGGBBAA' few operations need to be done so it can be used with PIXI. You need to convert the string to a number and also extract the alpha component to a separate variable. This can be done like this:
Remove the # symbol from the beginning of the color string: color.slice(1)
Convert color string to number type with the parseInt(...) global function.
Extract RGB values from color number with bit shifting.
Extract alpha component (last two characters) by bit manipulation.
// Convert color string to a number
const colorString = '#ffcc33aa';
const colorNumber = parseInt(colorString.slice(1), 16);
// Extract color components from color number
const rgb = colorNumber >>> 8;
const alpha = (colorNumber & 0xff) / 255;
// Apply obtained color components to a PIXI sprite
sprite.tint = rgb;
sprite.alpha = alpha;

Related

Auto adjusting decimal Format places as the input format in kotlin?

I am searching for a solution to use a decimal Format places to be as a variable depend on the edittext formating.
Example:
if the input is 2 digits after the dot (100.21)
the text vew will use same format DecimalFormat("#,###.##")
if the input is 4 digits (100.2135)
the textview will use same format (DecimalFormat("#,###.####"))
and so on.
so the formatting will change as per the input formatting.
# pattern character shows zero as absent, so "#,###.####" pattern will work for both cases:
import java.text.DecimalFormat
fun main() {
val format = DecimalFormat("#,###.####")
println(format.format(100.2135)) //100.2135
println(format.format(100.21)) //100.21
}
In Kotlin playground: https://pl.kotl.in/j0PveSblv

What colour format is used in command block commands?

I just started using command blocks in Minecraft and I'm stuck. I'm trying to make a custom firework rocket colour with this command.
give #p minecraft:firework_rocket{
Fireworks:{
Flight:2,
Explosions:[{
Type:1,
Flicker:0,
Trail:1,
Colors:[I;86219204], // What is this colour format?
FadeColors:[I;16886219] // same here
}]
}
} 1
I have tried with HEX and RGB and it doesn't seem like it's any of those.
For reference I;2651799 is cyan; I;1973019 is black; and I;15790320 is white.
I used this page to check these values by just ticking the boxes in the Select the Explosion Colors section, generating the command, and checking the value.
Thanks for your help,
Huky
I have tried with HEX and RGB and it doesn't seem like it's any of those.
But it is! Colors specified through NBT use the hex format (#RRGGBB). However, Minecraft's NBT parser does not support hexadecimal numbers, only base 10. So this means you have to convert between base 10 and hex. For example, the color #FF0000 in hex is 16711680 in base 10!

Labview converting hexformatted string to ascii

In labview I am trying to convert a hex string to ascii format. For example if I have a hexstring like: 09124E4F21CD0024FFFFFFFFFFFFFFFF the ascii version of this is : NO!Í or basically a bunch of illegible symbols. I tried using the labview functions of converting hexstring to number but they didn't work. How would I convert the ascii part to hexformatted ascii?
Hexadecimal String to Number works fine, but only for a hex string that represents a number that can be stored as a numeric data type:
If the input string represents a number outside the range of the
representation of number, number is set to the maximum value for that
data type.
Your example input is 128 bits long whereas the longest integer data type in current LabVIEW is 64 bits.
You can use this function, but you need to convert the input one byte at a time:
Create a While Loop and add a shift register. Initialise the shift register with your input string.
Inside the loop, wire the string from the shift register to the string input of a Search/Split String function
Wire a numeric constant of 2 to the offset input - i.e. split the string into the first two characters, and the rest
Wire the match + rest of string output to the right-hand shift register terminal
Wire the substring before match output to a Hexadecimal String to Number function
Wire the default input of this function to a numeric constant with value 0 and type U8
Wire the output of this function to the right-hand side of the While loop and make the terminal indexing (via right-click)
Use an Empty String/Path? function to exit the While loop when the string being passed back into the shift register is empty.
The output from the indexing terminal you created will now be a U8 (byte) array containing the data converted from the input string. If you want it in string form you can convert it using Byte Array to String.
This assumes that your input string is always a multiple of 2 characters in length. If you need it to handle an input such as "3F2" you'll need to check for this and do something to the input (I'll let you figure out what) before passing it into your loop.

iTextSharp - Incorrect text position

When extracting the position of the words in this example:
http://www.dertour.de/static/agb/2015/sommer/DER_Deutschland_So15.pdf
with iTextSharp 5.5.8
I'm getting 'incorrect' coordinates for some words. For example on line 17 of the first paragraph: 'gehen oder im Widerspruch zur Reiseaus-'
the x-values of the left,top position of the words are 118, 217, 296, 350, 524, 587. Only the first value seems correct (118,208,277,320,487,540). The x-value of the right-bottom point of the space-character between 'gehen' and 'oder' is 208, which seems correct and also seems to be the correct x-pos for the word 'oder'. Maybe it has something to do with the fillmode of the paragraph, but I'm not sure which actions I should perform to get the right coordinates.
I'm using LocationTextExtractionStrategy and calculate the word-positions to a 300 dpi coordinate system.
public override void RenderText(TextRenderInfo renderInfo)
{
// for the provided example
// uUnit = 1
// originX = 33.862
// originY = 33.555
// dpi = 300
// above values where calculated with code:
// PdfNumber userUnit = pageDict.GetAsNumber(PdfName.USERUNIT);
// if (userUnit != null)
// {
// uUnit = userUnit.FloatValue;
// }
// Rectangle dim = reader.GetPageSize(i);
// float originX = dim.Left;
// float originY = dim.Bottom;
// calculate coordinates:
renderInfo.GetText();
LineSegment segment = renderInfo.GetBaseline();
List<TextRenderInfo> charInfo = renderInfo.GetCharacterRenderInfos().ToList();
foreach (TextRenderInfo item in charInfo)
{
LineSegment char_segment = item.GetBaseline();
int char_left = (int)Math.Round((char_segment.GetStartPoint()[0] - originX) * dpi * uUnit / 72.0f);
int char_top = (int)Math.Round((item.GetAscentLine().GetEndPoint()[1] - originY) * dpi * uUnit / 72.0f);
int char_right = (int)Math.Round((char_segment.GetEndPoint()[0] - originX) * dpi * uUnit / 72.0f);
int char_bottom = (int)Math.Round((item.GetDescentLine().GetStartPoint()[1] - originY) * dpi * uUnit / 72.0f);
}
}
This indeed is a bug in iText & iTextSharp:
The lines with the extremely inaccurate x coordinates are those for which a large wordspacing value is set, e.g. your line:
0.2861 Tw T*
[<0047004500480045004E0000>-286<004F0044004500520000>-286<0049004D0000>-231<003700490044004500520053005000520055004300480000>-286<005A005500520000>-286<00320045004900530045004100550053000D>]TJ
(That 0.2861 argument for Tw is large.)
According to the ToUnicode map of the font in question the 0000 at the end of each word maps to the space character. Thus, iText here adds the word spacing value when calculating the x coordinates because according to the PDF specification ISO 32000-1:
Word spacing works the same way as character spacing but shall apply only to the ASCII SPACE character
(First sentence of section 9.3.3 Word Spacing)
Unfortunately it does not take into account
Word spacing shall be applied to every occurrence of the single-byte character code 32 in a string when using
a simple font or a composite font that defines code 32 as a single-byte code. It shall not apply to occurrences of
the byte value 32 in multiple-byte codes.
(Last sentence of section 9.3.3 Word Spacing)
At the 0000 above, therefore, word spacing must not be applied even though it is mapped to the space character because
the font encoding in question is purely multi-byte and
even in case of single-byte encoded space characters the word spacing is applied only at the single-byte code 32, not at a code which merely maps to the space character with ASCII code 32.
Usually this is not a problem during text extraction, usually PDF generators which encode space characters using multi-byte encodings are aware that word spacing does not apply for them and, therefore, don't change the word spacing from its default 0 value, so the iText bug here does no harm. Usage of word spacing instructions usually indicates that fonts are used which do map the single-byte code 32 to the space character.
Your PDF, on the other hand, seems to not have been created with that fact on the mind, it looks like first the word spacing has been set (0.2861 Tw), and after recognizing that it made no difference, explicit gaps have been added (-286 in the TJ instruction). (Or that was part of the development history of the PDF generator in question.)
Please be aware that positive values in the TJ argument mean a shift to the left, so negative values (as claimed for the -286 above) indeed widen or add gaps:
array TJ Show one or more text strings, allowing individual glyph positioning. Each element of array shall be either a string or a number. If the element is a string, this operator shall show the string. If it is a number, the operator shall adjust the text position by that amount; that is, it shall translate the text matrix, Tm . The number shall be expressed in thousandths of a unit of text space (see 9.4.4, "Text Space Details"). This amount shall be subtracted from the current horizontal or vertical coordinate, depending on the writing mode. In the default coordinate system, a positive adjustment has the effect of moving the next glyph painted either to the left or down by the given amount. Figure 46 shows an example of the effect of passing offsets to TJ.
(Table 109 – Text-showing operators in ISO 32000-1)

standard keyboard character not included in Base64?

I have a function that generates a random Base64 String
Public Shared Function GenerateSalt() As String
Dim rng As RNGCryptoServiceProvider = New RNGCryptoServiceProvider
Dim buff(94) As Byte
rng.GetBytes(buff)
Return Convert.ToBase64String(buff)
End Function
This will always return a 128 Character String. I then take that string and divide it into 4 substrings. I then merge that all back into one big string called MasterSalt like so
MasterSalt = (Salt.Substring(1,32)) + "©" + (Salt.Substring(32,32)) + "©" + etc...
I am doing this because I then put all of this into an array and say Split(MasterSalt, "©")
My concern is I am not overly confident in the stability of using "©" as the delimiter to define where the string should be split. However I have to use something that is not going to be included in the randomly generated base64string. I would like it to be something that can be found on a standard keyboard if possible. So to be clear my question is: is there a glyph or character on a standard keyboard that would never be included in a randomly generated base64string??
Base64 uses 64 characters to encode 6 bits of the content at a time as values 0-63;
A-Z (0-25)
a-z (26-51)
0-9 (52-61)
+ (62)
/ (63)
...and it uses = as filler at the end if required.
Any other character will be available for you to use as a delimiter, for example space, period and minus.