// Note that this never considers IsCanonical
            public int Compare(object o1, object o2)
            {
                CharMapping c1 = (CharMapping)o1;
                CharMapping c2 = (CharMapping)o2;

                return(CompareArray(c1.MapIndex, c2.MapIndex));
            }
        private void RebaseUCD()
        {
            mappings.Sort(comparer);
            // mappedChars[0] = 0. This assures that value 0 of
            // mapIndex means there is no mapping.
            int count = 1;

            int [] compressedMapping = new int [mappedCharCount];
            // Update map index.
            int [] newMapIndex = new int [mappings.Count];
            for (int mi = 0; mi < mappings.Count; mi++)
            {
                CharMapping m = (CharMapping)mappings [mi];
                if (mi > 0 && 0 == comparer.Compare(
                        mappings [mi - 1], mappings [mi]))
                {
                    newMapIndex [mi] = newMapIndex [mi - 1];
                    continue;
                }
                newMapIndex [mi] = count;
                for (int i = m.MapIndex; mappedChars [i] != 0; i++)
                {
                    compressedMapping [count++] = mappedChars [i];
                }
                compressedMapping [count++] = 0;
            }
            for (int mi = 0; mi < mappings.Count; mi++)
            {
                ((CharMapping)mappings [mi]).MapIndex = newMapIndex [mi];
            }

            int [] compressedMapIndex = new int [mapIndex.Length];
            foreach (CharMapping m in mappings)
            {
                if (m.CodePoint <= char.MaxValue)
                {
                    compressedMapIndex [NUtil.MapIdx(m.CodePoint)] = m.MapIndex;
                }
            }

            mappedChars     = compressedMapping;
            mapIndex        = compressedMapIndex;
            mappedCharCount = count;
        }
Exemplo n.º 3
0
        public void Read(FileReader reader, FFNT header, List <CMAP> CodeMaps)
        {
            uint CodeBegin = 0;
            uint CodeEnd   = 0;

            long pos = reader.Position;

            reader.ReadSignature(4, "CMAP");
            SectionSize = reader.ReadUInt32();
            if (header.Platform == FFNT.PlatformType.NX)
            {
                CodeBegin     = reader.ReadUInt32();
                CodeEnd       = reader.ReadUInt32();
                MappingMethod = reader.ReadEnum <Mapping>(true);
                Padding       = reader.ReadUInt16();
            }
            else
            {
                CodeBegin     = reader.ReadUInt16();
                CodeEnd       = reader.ReadUInt16();
                MappingMethod = reader.ReadEnum <Mapping>(true);
                Padding       = reader.ReadUInt16();
            }

            CharacterCodeBegin = (char)CodeBegin;
            CharacterCodeEnd   = (char)CodeEnd;

            uint NextMapOffset = reader.ReadUInt32();

            //Mapping methods from
https:      //github.com/IcySon55/Kuriimu/blob/f670c2719affc1eaef8b4c40e40985881247acc7/src/Cetera/Font/BFFNT.cs#L211
            switch (MappingMethod)
            {
            case Mapping.Direct:
                var charOffset = reader.ReadUInt16();
                for (char i = CharacterCodeBegin; i <= CharacterCodeEnd; i++)
                {
                    int idx = i - CharacterCodeBegin + charOffset;
                    header.FontSection.CodeMapDictionary[i] = idx < ushort.MaxValue ? idx : 0;
                }

                MappingData = new CMAPDirect();
                ((CMAPDirect)MappingData).Offset = charOffset;
                break;

            case Mapping.Table:
                List <short> table = new List <short>();
                for (char i = CharacterCodeBegin; i <= CharacterCodeEnd; i++)
                {
                    short idx = reader.ReadInt16();
                    if (idx != -1)
                    {
                        header.FontSection.CodeMapDictionary[i] = idx;
                    }

                    table.Add(idx);
                }

                MappingData = new CMAPIndexTable();
                ((CMAPIndexTable)MappingData).Table = table.ToArray();
                break;

            case Mapping.Scan:
                var CharEntryCount = reader.ReadUInt16();

                if (header.Platform == FFNT.PlatformType.NX)
                {
                    reader.ReadUInt16();     //Padding
                }
                uint[]  codes   = new uint[CharEntryCount];
                short[] indexes = new short[CharEntryCount];

                for (int i = 0; i < CharEntryCount; i++)
                {
                    if (header.Platform == FFNT.PlatformType.NX)
                    {
                        uint  charCode = reader.ReadUInt32();
                        short index    = reader.ReadInt16();
                        short padding  = reader.ReadInt16();
                        if (index != -1)
                        {
                            header.FontSection.CodeMapDictionary[(char)charCode] = index;
                        }

                        codes[i]   = charCode;
                        indexes[i] = index;
                    }
                    else
                    {
                        ushort charCode = reader.ReadUInt16();
                        short  index    = reader.ReadInt16();
                        if (index != -1)
                        {
                            header.FontSection.CodeMapDictionary[(char)charCode] = index;
                        }

                        codes[i]   = charCode;
                        indexes[i] = index;
                    }
                }

                MappingData = new CMAPScanMapping();
                ((CMAPScanMapping)MappingData).Codes   = codes;
                ((CMAPScanMapping)MappingData).Indexes = indexes;
                break;
            }

            if (NextMapOffset != 0)
            {
                reader.SeekBegin(NextMapOffset - 8);
                NextCodeMapSection = new CMAP();
                NextCodeMapSection.Read(reader, header, CodeMaps);
                CodeMaps.Add(NextCodeMapSection);
            }
            else
            {
                reader.SeekBegin(pos + SectionSize);
            }
        }
Exemplo n.º 4
0
		/// <summary>
		/// Find the next character mapping marker in the string (if any).
		/// </summary>
		private int IndexOfFirstCharMappingMarker(string sText, out CharMapping cmText)
		{
			int idx = -1;
			cmText = null;
			foreach (CharMapping cm in m_rgcm)
			{
				if (cm.BeginMarker.Length == 0)
					continue;
				int idxT = sText.IndexOf(cm.BeginMarker);
				if (idxT != -1)
				{
					if (idx == -1 || idxT < idx)
					{
						cmText = cm;
						idx = idxT;
					}
				}
			}
			return idx;
		}
Exemplo n.º 5
0
		private void ReadCharMapping(XmlNode xn)
		{
			CharMapping cm = new CharMapping(xn);
			m_rgcm.Add(cm);
		}
Exemplo n.º 6
0
		private ListViewItem CreateListItemForCharMapping(CharMapping cm)
		{
			string sWsName = String.Empty;
			string sWs = cm.DestinationWritingSystemId;
			if (!string.IsNullOrEmpty(sWs))
			{
				IWritingSystem ws;
				m_cache.ServiceLocator.WritingSystemManager.GetOrSet(sWs, out ws);
				Debug.Assert(ws != null);
				sWsName = ws.DisplayLabel;
			}
			string sStyle = cm.DestinationStyle;
			if (sStyle == null)
				sStyle = String.Empty;
			string sBegin = cm.BeginMarker;
			if (sBegin == null)
				sBegin = String.Empty;
			string sEnd = cm.EndMarker;
			if (sEnd == null)
				sEnd = String.Empty;
			return new ListViewItem(new[] { sBegin, sEnd, sWsName, sStyle }) {Tag = cm};
		}
Exemplo n.º 7
0
		private void btnAddCharMapping_Click(object sender, EventArgs e)
		{
			using (ImportCharMappingDlg dlg = new ImportCharMappingDlg())
			{
				IApp app = (IApp)m_mediator.PropertyTable.GetValue("App");
				dlg.Initialize(m_cache, m_mediator.HelpTopicProvider, app, m_stylesheet, null);
				if (dlg.ShowDialog(this) == DialogResult.OK)
				{
					CharMapping cmNew = new CharMapping();
					cmNew.BeginMarker = dlg.BeginMarker;
					cmNew.EndMarker = dlg.EndMarker;
					cmNew.EndWithWord = dlg.EndWithWord;
					cmNew.DestinationWritingSystemId = dlg.WritingSystemId;
					cmNew.DestinationStyle = dlg.StyleName;
					cmNew.IgnoreMarkerOnImport = dlg.IgnoreOnImport;
					m_rgcm.Add(cmNew);
					ListViewItem lvi = CreateListItemForCharMapping(cmNew);
					m_lvCharMappings.Items.Add(lvi);
					m_fDirtySettings = true;
				}
			}
		}