Unicode hexadecimal code always converting to ?
$sOutputDir = "C:\Users\erics_000\Desktop\Output"

$sCharsDir = "$sOutputDir\Chars"

$sCombDir = "$sOutputDir\Comb"

$sImageMagickHome = "C:\ImageMagick"

$sImageMagickConv = "$sImageMagickHome\convert.exe"

New-Item -ItemType Directory -Force -Path $sOutputDir

New-Item -ItemType Directory -Force -Path $sCharsDir

New-Item -ItemType Directory -Force -Path $sCombDir

Function outputPNG( $begin, $end, $font )
{
	for ( $i = $begin; $i -le $end; $i++ )
	{
		$sCurChar = [char]$i
		
		Write-Host $sCurChar 
		
		$sCurLabel = [string]$sCurChar
		
		If($sCurLabel -contains " ")
		{
		
		}
		ElseIf($sCurLabel -contains "")
		{
		
		}
		Else
		{
			If( Test-Path mychar.txt )
			{
				Remove-Item mychar.txt
			}
			
			Add-Content mychar.txt $sCurLabel
			
			Write-Host $sCurLabel
			
			$sCurFileName = [string]"{0:X0000}" -f $i+".png"
			
			$sImageMagickArgs = @('-background', 'transparent', 
						'-fill', 'hsb(0,0,0)', 
						'-font', "$font",
						'-density','90',
						'-pointsize', '18',
						'-gravity', 'center',
						"label:""@mychar.txt""",
						"$sCharsDir\$sCurFileName")
							
			Write-Host $sImageMagickConv $sImageMagickArgs
			
			& $sImageMagickConv $sImageMagickArgs
		}
	}
}

outputPNG 0x0020 0x007F "Arial"	#Basic Latin	 	2580  259F  	Block Elements
outputPNG 0x0600 0x06FF "Andalus" 	#Arabic	 	2F00 2FDF  	Kangxi Radicals

The basic lating characters seem to convert fine with the use of [char]0xCODE. The arabic range however always seems to be converted to a '?' for every hexadecimal code in that range. I tried changing fonts and using Arial or Andulus however the problem seems to be occurring before the use of the ImageMagick command in the actual conversion using [char] which for some reason doesn't seem to convert the Arabic codes to their corresponding character.

Example output:

C:\ImageMagick\convert.exe -background transparent -fill hsb(0,0,0) -font Andalus -density 90 -pointsize 18 -gravity center label:"@mychar.txt" C:\Users\erics_0
00\Desktop\Output\Chars\6FB.png
?
?
C:\ImageMagick\convert.exe -background transparent -fill hsb(0,0,0) -font Andalus -density 90 -pointsize 18 -gravity center label:"@mychar.txt" C:\Users\erics_0
00\Desktop\Output\Chars\6FC.png
?
?
C:\ImageMagick\convert.exe -background transparent -fill hsb(0,0,0) -font Andalus -density 90 -pointsize 18 -gravity center label:"@mychar.txt" C:\Users\erics_0
00\Desktop\Output\Chars\6FD.png
?
?
C:\ImageMagick\convert.exe -background transparent -fill hsb(0,0,0) -font Andalus -density 90 -pointsize 18 -gravity center label:"@mychar.txt" C:\Users\erics_0
00\Desktop\Output\Chars\6FE.png
?
?
C:\ImageMagick\convert.exe -background transparent -fill hsb(0,0,0) -font Andalus -density 90 -pointsize 18 -gravity center label:"@mychar.txt" C:\Users\erics_0
00\Desktop\Output\Chars\6FF.png

Thank you...


July 11th, 2015 2:10am

May have something to do with encoding.
Free Windows Admin Tool Kit Click here and download it now
July 11th, 2015 2:27am

I tried invoking:

$OutputEncoding = [Console]::OutputEncoding

before running my script. That does not seem to be the problem. It's still converting Arabic to '?'s. The output:

PS C:\Users\erics_000\AndroidStudioProjects\OpenGLTextManager> $outputEncoding


IsSingleByte      : True
BodyName          : IBM437
EncodingName      : OEM United States
HeaderName        : IBM437
WebName           : IBM437
WindowsCodePage   : 1252
IsBrowserDisplay  : False
IsBrowserSave     : False
IsMailNewsDisplay : False
IsMailNewsSave    : False
EncoderFallback   : System.Text.InternalEncoderBestFitFallback
DecoderFallback   : System.Text.InternalDecoderBestFitFallback
IsReadOnly        : True
CodePage          : 437



PS C:\Users\erics_000\AndroidStudioProjects\OpenGLTextManager>

seems to imply that the encoding is for the United States but I probably want to see UTF8 or something international. I don't really know how to set that encoding yet...

July 11th, 2015 2:39am

Try one of these:

[Console]::OutputEncoding = New-Object -typename System.Text.UTF8Encoding
$OutputEncoding = New-Object -typename System.Text.UTF8Encoding

Free Windows Admin Tool Kit Click here and download it now
July 11th, 2015 2:51am

Before I run my script I checked encoding:

BodyName          : utf-8
EncodingName      : Unicode (UTF-8)
HeaderName        : utf-8
WebName           : utf-8
WindowsCodePage   : 1200
IsBrowserDisplay  : True
IsBrowserSave     : True
IsMailNewsDisplay : True
IsMailNewsSave    : True
IsSingleByte      : False
EncoderFallback   : System.Text.EncoderReplacementFallback
DecoderFallback   : System.Text.DecoderReplacementFallback
IsReadOnly        : True
CodePage          : 65001

Still I see a lot of '?''s and no Arabic.

July 11th, 2015 3:05am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics