// This method is for the data cache but should be used later once the // the constructor that sets the number of glyphs is used public longHorMetric GetOrMakeHMetric(uint i) { if (m_nGlyphsInTheFont == 0) { throw new ArgumentException("Number of Glyphs has not been set."); } else if (i >= m_nGlyphsInTheFont) { throw new ArgumentOutOfRangeException(); } longHorMetric hm = new longHorMetric(); if (i < m_nNumberOfHMetrics) { hm.advanceWidth = m_bufTable.GetUshort(i * 4); hm.lsb = m_bufTable.GetShort(i * 4 + 2); } else { hm.advanceWidth = m_bufTable.GetUshort(((uint)m_nNumberOfHMetrics - 1) * 4); hm.lsb = m_bufTable.GetShort((uint)m_nNumberOfHMetrics * 4 + ((i - m_nNumberOfHMetrics) * 2)); } return(hm); }
// Does the real work of adding protected bool addToLongHorMetric(ushort nIndex, ushort nAdvanceWidth, short nLeftSideBearing) { bool bResult = true; // NOTE: This might not be OK we might want to add a glyph that is much greater the the number that is there now if (nIndex >= m_nGlyphsInTheFont) { bResult = false; throw new ArgumentOutOfRangeException("Tried to add a Vertical Matric to a position greater than the number of Glyphs + 1."); } else { // if we are adding a horiz matrix that is less the the number of NumberOfHMetrics // we need to adjust for this so we know how to write it later and fix up the hhea_table if (nIndex < m_nNumberOfHMetrics || (nIndex == m_nNumberOfHMetrics && nAdvanceWidth != 0)) { m_nNumberOfHMetrics++; Table_hhea.hhea_cache hheaCache = (Table_hhea.hhea_cache)m_hheaTable.GetCache(); hheaCache.numberOfHMetrics++; } // NOTE: Table maxp and ltsh numGlyphs isn't being dynamically updated m_nGlyphsInTheFont++; longHorMetric lhm = new longHorMetric(); lhm.advanceWidth = nAdvanceWidth; lhm.lsb = nLeftSideBearing; m_longHorMetric.Insert(nIndex, lhm); m_bDirty = true; } return(bResult); }
public longHorMetric GetHMetric(uint i, OTFont fontOwner) { if (i >= GetNumberOfHMetrics(fontOwner)) { throw new ArgumentOutOfRangeException("i"); } longHorMetric hm = new longHorMetric(); hm.advanceWidth = m_bufTable.GetUshort(i*4); hm.lsb = m_bufTable.GetShort(i*4+2); return hm; }
public longHorMetric GetHMetric(uint i, OTFont fontOwner) { if (i >= GetNumberOfHMetrics(fontOwner)) { throw new ArgumentOutOfRangeException("i"); } longHorMetric hm = new longHorMetric(); hm.advanceWidth = m_bufTable.GetUshort(i * 4); hm.lsb = m_bufTable.GetShort(i * 4 + 2); return(hm); }
public List <short> leftSideBearings; // Left side bearings for glyph IDs greater than or equal to numberOfHMetrics. public void Read(TTFReader r, int numberOfHMetrics, int numGlyphs) { this.hMetrics = new List <longHorMetric>(); for (int i = 0; i < numberOfHMetrics; ++i) { longHorMetric lhm = new longHorMetric(); r.ReadInt(out lhm.advanceWidth); r.ReadInt(out lhm.lsb); this.hMetrics.Add(lhm); } this.leftSideBearings = new List <short>(); // We could have them pass in the numGlyphs-numberOfHMetrics instead of // calculating this ourselves, but I think this helps add rigor. for (int i = 0; i < numGlyphs - numberOfHMetrics; ++i) { this.leftSideBearings.Add(r.ReadInt16()); } }
// Just as you would expect this returns a requested longHorMetric public longHorMetric GetOrMakeHMetric(ushort nIndex) { longHorMetric lm = new longHorMetric(); if (nIndex >= m_nGlyphsInTheFont) { throw new ArgumentOutOfRangeException("Tried to access a Horiz Matric that does not exist."); } else if (nIndex >= m_nNumberOfHMetrics) { lm.advanceWidth = ((longHorMetric)m_longHorMetric[m_nNumberOfHMetrics - 1]).advanceWidth; lm.lsb = ((longHorMetric)m_longHorMetric[m_nNumberOfHMetrics - 1]).lsb; } else { lm.advanceWidth = ((longHorMetric)m_longHorMetric[nIndex]).advanceWidth; lm.lsb = ((longHorMetric)m_longHorMetric[nIndex]).lsb; } return(lm); }
public longHorMetric GetOrMakeHMetric(uint i, OTFont fontOwner) { longHorMetric hm = null; m_nGlyphsInTheFont = fontOwner.GetMaxpNumGlyphs(); m_nNumberOfHMetrics = GetNumberOfHMetrics(fontOwner); uint nlsb = GetNumLeftSideBearingEntries(fontOwner); uint CalcTableLength = (uint)m_nNumberOfHMetrics * 4 + nlsb * 2; if (i >= m_nGlyphsInTheFont) { throw new ArgumentOutOfRangeException(); } // only try to parse out the data if the table length is correct if (CalcTableLength == GetLength()) { hm = GetOrMakeHMetric(i); } return(hm); }
/************************ * public methods */ public bool Validate(Validator v, OTFontVal fontOwner) { bool bRet = true; Table_hhea hheaTable = (Table_hhea)fontOwner.GetTable("hhea"); if (hheaTable == null) { v.Error(T.T_NULL, E._TEST_E_TableMissing, m_tag, "Unable to test this table, hhea table is invalid or missing"); return(false); } Table_maxp maxpTable = (Table_maxp)fontOwner.GetTable("maxp"); if (maxpTable == null) { v.Error(T.T_NULL, E._TEST_E_TableMissing, m_tag, "Unable to test this table, maxp table is invalid or missing"); return(false); } if (v.PerformTest(T.hmtx_TableSize)) { uint nhm = GetNumberOfHMetrics(fontOwner); uint nlsb = GetNumLeftSideBearingEntries(fontOwner); uint CalcTableLength = nhm * 4 + nlsb * 2; if (CalcTableLength == GetLength()) { v.Pass(T.hmtx_TableSize, P.hmtx_P_TableSize, m_tag); } else { v.Error(T.hmtx_TableSize, E.hmtx_E_TableSize, m_tag); bRet = false; } } if (v.PerformTest(T.hmtx_CheckMetrics)) { bool bMetricsOk = true; for (uint iGlyph = 0; iGlyph < fontOwner.GetMaxpNumGlyphs(); iGlyph++) { longHorMetric hm = this.GetOrMakeHMetric(iGlyph, fontOwner); if (hm != null) { if (hm.lsb > hm.advanceWidth) { v.Warning(T.hmtx_CheckMetrics, W.hmtx_W_CheckMetrics_lsb_gt_adv, m_tag, "glyph# " + iGlyph); bMetricsOk = false; } } else { // unable to fetch this horizontal metric // (probably bad hheaTable.numberOfHMetrics or bad table length) bMetricsOk = false; } } if (bMetricsOk) { v.Pass(T.hmtx_CheckMetrics, P.hmtx_P_CheckMetrics, m_tag); } } return(bRet); }
// This method is for the data cache but should be used later once the // the constructor that sets the number of glyphs is used public longHorMetric GetOrMakeHMetric( uint i ) { if( m_nGlyphsInTheFont == 0 ) { throw new ArgumentException( "Number of Glyphs has not been set." ); } else if( i >= m_nGlyphsInTheFont ) { throw new ArgumentOutOfRangeException(); } longHorMetric hm = new longHorMetric(); if (i < m_nNumberOfHMetrics) { hm.advanceWidth = m_bufTable.GetUshort(i*4); hm.lsb = m_bufTable.GetShort(i*4+2); } else { hm.advanceWidth = m_bufTable.GetUshort(((uint)m_nNumberOfHMetrics-1)*4); hm.lsb = m_bufTable.GetShort((uint)m_nNumberOfHMetrics*4 + ((i - m_nNumberOfHMetrics)*2)); } return hm; }
// Does the real work of adding protected bool addToLongHorMetric( ushort nIndex, ushort nAdvanceWidth, short nLeftSideBearing ) { bool bResult = true; // NOTE: This might not be OK we might want to add a glyph that is much greater the the number that is there now if( nIndex >= m_nGlyphsInTheFont ) { bResult = false; throw new ArgumentOutOfRangeException("Tried to add a Vertical Matric to a position greater than the number of Glyphs + 1."); } else { // if we are adding a horiz matrix that is less the the number of NumberOfHMetrics // we need to adjust for this so we know how to write it later and fix up the hhea_table if( nIndex < m_nNumberOfHMetrics || (nIndex == m_nNumberOfHMetrics && nAdvanceWidth != 0)) { m_nNumberOfHMetrics++; Table_hhea.hhea_cache hheaCache = (Table_hhea.hhea_cache)m_hheaTable.GetCache(); hheaCache.numberOfHMetrics++; } // NOTE: Table maxp and ltsh numGlyphs isn't being dynamically updated m_nGlyphsInTheFont++; longHorMetric lhm = new longHorMetric(); lhm.advanceWidth = nAdvanceWidth; lhm.lsb = nLeftSideBearing; m_longHorMetric.Insert( nIndex, lhm ); m_bDirty = true; } return bResult; }
// Just as you would expect this returns a requested longHorMetric public longHorMetric GetOrMakeHMetric( ushort nIndex ) { longHorMetric lm = new longHorMetric(); if( nIndex >= m_nGlyphsInTheFont ) { throw new ArgumentOutOfRangeException("Tried to access a Horiz Matric that does not exist."); } else if( nIndex >= m_nNumberOfHMetrics ) { lm.advanceWidth = ((longHorMetric)m_longHorMetric[m_nNumberOfHMetrics - 1]).advanceWidth; lm.lsb = ((longHorMetric)m_longHorMetric[m_nNumberOfHMetrics - 1]).lsb; } else { lm.advanceWidth = ((longHorMetric)m_longHorMetric[nIndex]).advanceWidth; lm.lsb = ((longHorMetric)m_longHorMetric[nIndex]).lsb; } return lm; }