示例#1
0
 public void Print(TextWriter writer, int nTabs)
 {
     Logging.PrintTabs(writer, nTabs); writer.Write("( ");
     m_Object.Print(writer, nTabs + 1); writer.Write("\n");
     if (m_ActionSlots.Size != 0)
     {
         Logging.PrintTabs(writer, nTabs + 1); writer.Write(":ActionSlots (\n");
         for (int i = 0; i < m_ActionSlots.Size; i++)
         {
             Logging.PrintTabs(writer, nTabs + 2); writer.Write("(\n");
             MHActionSequence pActions = m_ActionSlots.GetAt(i);
             if (pActions.Size == 0)
             {
                 writer.Write("NULL\n");
             }
             else
             {
                 pActions.Print(writer, nTabs + 2);
             }
             Logging.PrintTabs(writer, nTabs + 2); writer.Write(")\n");
         }
         Logging.PrintTabs(writer, nTabs + 1); writer.Write(")\n");
     }
     Logging.PrintTabs(writer, nTabs); writer.Write(")\n");
 }
示例#2
0
 public virtual void CastToContentRef(MHObjectRef success, MHSequence <MHParameter> args, MHEngine engine)
 {
     // Converts a string to a ContentRef.
     if (args.Size == 2)
     {
         MHOctetString str = new MHOctetString();
         GetString(args.GetAt(0), str, engine);
         MHContentRef result = new MHContentRef();
         result.ContentRef.Copy(str);
         engine.FindObject(args.GetAt(1).GetReference()).SetVariableValue(new MHUnion(result));
         SetSuccessFlag(success, true, engine);
     }
     else
     {
         SetSuccessFlag(success, false, engine);
     }
 }
示例#3
0
 public void Print(TextWriter writer, int nTabs)
 {
     Logging.PrintTabs(writer, nTabs); writer.Write("( ");
     for (int i = 0; i < m_Movement.Size; i++)
     {
         writer.Write("{0} ", m_Movement.GetAt(i));
     }
     writer.Write(")\n");
 }
示例#4
0
 protected override void PrintArgs(TextWriter writer, int nTabs)
 {
     writer.Write(" ( ");
     for (int i = 0; i < m_Points.Size; i++)
     {
         m_Points.GetAt(i).Print(writer, 0);
     }
     writer.Write(" )\n");
 }
示例#5
0
 protected override void PrintArgs(TextWriter writer, int nTabs)
 {
     m_Succeeded.Print(writer, nTabs);
     writer.Write(" ( ");
     for (int i = 0; i < m_Parameters.Size; i++)
     {
         m_Parameters.GetAt(i).Print(writer, 0);
     }
     writer.Write(" )\n");
 }
示例#6
0
        public virtual void GetCurrentDate(MHObjectRef success, MHSequence <MHParameter> args, MHEngine engine)
        {
            if (args.Size == 2)
            {
                DateTime dt             = new DateTime(1858, 11, 17);
                DateTime now            = DateTime.Now;
                int      nModJulianDate = now.Subtract(dt).Days;

                int nTimeAsSecs = (int)now.TimeOfDay.TotalSeconds;

                engine.FindObject(args.GetAt(0).GetReference()).SetVariableValue(new MHUnion(nModJulianDate));
                engine.FindObject(args.GetAt(1).GetReference()).SetVariableValue(new MHUnion(nTimeAsSecs));
                SetSuccessFlag(success, true, engine);
            }
            else
            {
                SetSuccessFlag(success, false, engine);
            }
        }
示例#7
0
 protected override void PrintArgs(TextWriter writer, int nTabs)
 {
     m_Succeeded.Print(writer, nTabs);
     writer.Write(" ( ");
     for (int i = 0; i < m_Variables.Size; i++)
     {
         m_Variables.GetAt(i).Print(writer, 0);
     }
     writer.Write(" ) ");
     m_FileName.Print(writer, nTabs);
 }
示例#8
0
 public override void Print(TextWriter writer, int nTabs)
 {
     Logging.PrintTabs(writer, nTabs); writer.Write("{:ListGroup ");
     base.PrintContents(writer, nTabs);
     Logging.PrintTabs(writer, nTabs + 1); writer.Write(":Positions (");
     for (int i = 0; i < m_Positions.Size; i++)
     {
         writer.Write(" ( {0} {1} )", m_Positions.GetAt(i).X, m_Positions.GetAt(i).Y);
     }
     writer.Write(")\n");
     if (m_fWrapAround)
     {
         Logging.PrintTabs(writer, nTabs + 1); writer.Write(":WrapAround true\n");
     }
     if (m_fMultipleSelection)
     {
         Logging.PrintTabs(writer, nTabs + 1); writer.Write(":MultipleSelection true\n");
     }
     Logging.PrintTabs(writer, nTabs); writer.Write("}\n");
 }
示例#9
0
 // Returns the index on the stack or -1 if it's not there.
 public int FindOnStack(MHRoot pVis)
 {
     for (int i = 0; i < m_DisplayStack.Size; i++)
     {
         if (m_DisplayStack.GetAt(i).Equals(pVis))
         {
             return(i);
         }
     }
     return(-1); // Not there
 }
示例#10
0
 public virtual void SI_GetServiceIndex(MHObjectRef success, MHSequence <MHParameter> args, MHEngine engine)
 {
     // Returns an index indicating the service
     if (args.Size == 2)
     {
         MHOctetString str = new MHOctetString();
         GetString(args.GetAt(0), str, engine);
         MHParameter pResInt = args.GetAt(1);
         // The format of the service is dvb://netID.[transPortID].serviceID
         // where the IDs are in hex.
         // or rec://svc/lcn/N where N is the "logical channel number" i.e. the Freeview channel.
         int nResult = engine.GetContext().GetChannelIndex(str.ToString());
         engine.FindObject(pResInt.GetReference()).SetVariableValue(new MHUnion(nResult));
         Logging.Log(Logging.MHLogDetail, "Get service index for " + str.Printable() + " - result " + nResult);
         SetSuccessFlag(success, true, engine);
     }
     else
     {
         SetSuccessFlag(success, false, engine);
     }
 }
示例#11
0
 protected void PrintContents(TextWriter writer, int nTabs)
 {
     base.Print(writer, nTabs + 1);
     if (m_MovementTable.Size != 0)
     {
         Logging.PrintTabs(writer, nTabs + 1); writer.Write(":MovementTable (\n");
         for (int i = 0; i < m_MovementTable.Size; i++)
         {
             m_MovementTable.GetAt(i).Print(writer, nTabs + 2);
         }
         Logging.PrintTabs(writer, nTabs + 1); writer.Write(")\n");
     }
     if (m_TokenGrpItems.Size != 0)
     {
         Logging.PrintTabs(writer, nTabs + 1); writer.Write(":TokenGroupItems (\n");
         for (int i = 0; i < m_TokenGrpItems.Size; i++)
         {
             m_TokenGrpItems.GetAt(i).Print(writer, nTabs + 2);
         }
         Logging.PrintTabs(writer, nTabs + 1); writer.Write(")\n");
     }
     if (m_NoTokenActionSlots.Size != 0)
     {
         Logging.PrintTabs(writer, nTabs + 1); writer.Write(":NoTokenActionSlots (\n");
         for (int i = 0; i < m_NoTokenActionSlots.Size; i++)
         {
             MHActionSequence pActions = m_NoTokenActionSlots.GetAt(i);
             if (pActions.Size == 0)
             {
                 Logging.PrintTabs(writer, nTabs + 2); writer.Write("NULL ");
             }
             else
             {
                 pActions.Print(writer, nTabs + 2);
             }
         }
         Logging.PrintTabs(writer, nTabs + 1); writer.Write(")\n");
     }
 }
示例#12
0
 public virtual void SI_TuneIndex(MHObjectRef success, MHSequence <MHParameter> args, MHEngine engine)
 {
     // Tunes to an index returned by GSI
     if (args.Size == 1)
     {
         int  nChannel = GetInt(args.GetAt(0), engine);
         bool res      = engine.GetContext().TuneTo(nChannel);
         SetSuccessFlag(success, res, engine);
     }
     else
     {
         SetSuccessFlag(success, false, engine);
     }
 }
示例#13
0
 public virtual void GetSubString(MHObjectRef success, MHSequence <MHParameter> args, MHEngine engine)
 {
     if (args.Size == 4)
     {
         // Extract a sub-string from a string.
         MHOctetString str = new MHOctetString();
         GetString(args.GetAt(0), str, engine);
         int nBeginExtract = GetInt(args.GetAt(1), engine);
         int nEndExtract   = GetInt(args.GetAt(2), engine);
         if (nBeginExtract < 1)
         {
             nBeginExtract = 1;
         }
         if (nBeginExtract > str.Size)
         {
             nBeginExtract = str.Size;
         }
         if (nEndExtract < 1)
         {
             nEndExtract = 1;
         }
         if (nEndExtract > str.Size)
         {
             nEndExtract = str.Size;
         }
         MHParameter pResString = args.GetAt(3);
         // Returns beginExtract to endExtract inclusive.
         engine.FindObject(pResString.GetReference()).SetVariableValue(
             new MHUnion(new MHOctetString(str, nBeginExtract - 1, nEndExtract - nBeginExtract + 1)));
         SetSuccessFlag(success, true, engine);
     }
     else
     {
         SetSuccessFlag(success, false, engine);
     }
 }
示例#14
0
        public virtual void WhoAmI(MHObjectRef success, MHSequence <MHParameter> args, MHEngine engine)
        {
            // Return a concatenation of the strings we respond to in
            // GetEngineSupport(UKEngineProfile(X))

            if (args.Size == 1)
            {
                MHOctetString result = new MHOctetString();
                result.Copy(MHEngine.MHEGEngineProviderIdString);
                result.Append(" ");
                result.Append(engine.GetContext().GetReceiverId());
                result.Append(" ");
                result.Append(engine.GetContext().GetDSMCCId());
                engine.FindObject((args.GetAt(0).GetReference())).SetVariableValue(new MHUnion(result));
                SetSuccessFlag(success, true, engine);
            }
            else
            {
                SetSuccessFlag(success, false, engine);
            }
        }
示例#15
0
 public override void Print(TextWriter writer, int nTabs)
 {
     Logging.PrintTabs(writer, nTabs); writer.Write("{:Stream ");
     base.Print(writer, nTabs + 1);
     Logging.PrintTabs(writer, nTabs + 1); writer.Write(":Multiplex (\n");
     for (int i = 0; i < m_Multiplex.Size; i++)
     {
         m_Multiplex.GetAt(i).Print(writer, nTabs + 2);
     }
     Logging.PrintTabs(writer, nTabs + 1); writer.Write(" )\n");
     if (m_nStorage != ST_Stream)
     {
         Logging.PrintTabs(writer, nTabs + 1); writer.Write(":Storage memory\n");
     }
     if (m_nLooping != 0)
     {
         Logging.PrintTabs(writer, nTabs + 1); writer.Write(":Looping {0}\n", m_nLooping);
     }
     Logging.PrintTabs(writer, nTabs); writer.Write("}\n");
 }
示例#16
0
        public virtual void FormatDate(MHObjectRef success, MHSequence <MHParameter> args, MHEngine engine)
        {
            if (args.Size == 4)
            {
                // This is a bit like strftime but not quite.
                MHOctetString format = new MHOctetString();
                GetString(args.GetAt(0), format, engine);
                int date = GetInt(args.GetAt(1), engine); // As produced in GCD
                int time = GetInt(args.GetAt(2), engine);

                string result = "";

                DateTime dt = new DateTime(1858, 11, 17);
                dt = dt.AddDays(date).AddSeconds(time);

                for (int i = 0; i < format.Size; i++)
                {
                    char   ch = format.GetAt(i);
                    string part; // Largest text is 4 chars for a year + null terminator
                    if (ch == '%')
                    {
                        i++;
                        if (i == format.Size)
                        {
                            break;
                        }
                        ch = format.GetAt(i);
                        switch (ch)
                        {
                        case 'Y': part = dt.ToString("yyyy"); break;

                        case 'y': part = dt.ToString("yy"); break;

                        case 'X': part = dt.ToString("MM"); break;

                        case 'x': part = dt.ToString("%M"); break;

                        case 'D': part = dt.ToString("dd"); break;

                        case 'd': part = dt.ToString("%d"); break;

                        case 'H': part = dt.ToString("HH"); break;

                        case 'h': part = dt.ToString("%H"); break;

                        case 'I': part = dt.ToString("hh"); break;

                        case 'i': part = dt.ToString("%h"); break;

                        case 'M': part = dt.ToString("mm"); break;

                        case 'm': part = dt.ToString("%m"); break;

                        case 'S': part = dt.ToString("ss"); break;

                        case 's': part = dt.ToString("%s"); break;

                        // TODO: These really should be localised.
                        case 'A': part = dt.ToString("tt"); break;

                        case 'a': part = dt.ToString("tt").ToLower(); break;

                        default: part = ""; break;
                        }
                        result += part;
                    }
                    else
                    {
                        result += ch;
                    }
                }
                MHOctetString theResult  = new MHOctetString(result);
                MHParameter   pResString = args.GetAt(3);
                engine.FindObject(pResString.GetReference()).SetVariableValue(new MHUnion(theResult));
                SetSuccessFlag(success, true, engine);
            }
            else
            {
                SetSuccessFlag(success, false, engine);
            }
        }
示例#17
0
        // UK MHEG specifies the use of the Tiresias font and broadcasters appear to
        // assume that all MHEG applications will lay the text out in the same way.

        // Recreate the image.
        protected void Redraw()
        {
            if (!RunningStatus || m_pDisplay == null)
            {
                return;
            }
            if (m_nBoxWidth == 0 || m_nBoxHeight == 0)
            {
                return;                                        // Can't draw zero sized boxes.
            }
            m_pDisplay.SetSize(m_nBoxWidth, m_nBoxHeight);
            m_pDisplay.Clear();

            MHRgba textColour = GetColour(m_textColour);
            // Process any escapes in the text and construct the text arrays.
            MHSequence <MHTextLine> theText = new MHSequence <MHTextLine>();
            // Set up the first item on the first line.
            MHTextItem pCurrItem = new MHTextItem();
            MHTextLine pCurrLine = new MHTextLine();

            pCurrLine.Items.Append(pCurrItem);
            theText.Append(pCurrLine);
            Stack <MHRgba> m_ColourStack = new Stack <MHRgba>(); // Stack to handle nested colour codes.

            m_ColourStack.Push(textColour);
            pCurrItem.Colour = textColour;

            int i = 0;

            while (i < m_Content.Size)
            {
                char ch = m_Content.GetAt(i++);

                if (ch == '\t')   // Tab - start a new item if we have any text in the existing one.
                {
                    if (pCurrItem.Text.Size != 0)
                    {
                        pCurrItem = pCurrItem.NewItem();
                        pCurrLine.Items.Append(pCurrItem);
                    }
                    pCurrItem.TabCount++;
                }

                else if (ch == '\r')   // CR - line break.
                // TODO: Two CRs next to one another are treated as </P> rather than <BR><BR>
                // This should also include the sequence CRLFCRLF.
                {
                    pCurrLine = new MHTextLine();
                    theText.Append(pCurrLine);
                    pCurrItem = pCurrItem.NewItem();
                    pCurrLine.Items.Append(pCurrItem);
                }

                else if (ch == 0x1b)   // Escape - special codes.
                {
                    if (i == m_Content.Size)
                    {
                        break;
                    }
                    char code = m_Content.GetAt(i);
                    // The only codes we are interested in are the start and end of colour.
                    // TODO: We may also need "bold" and some hypertext colours.

                    if (code >= 0x40 && code <= 0x5e)   // Start code
                    // Start codes are followed by a parameter count and a number of parameter bytes.
                    {
                        if (++i == m_Content.Size)
                        {
                            break;
                        }
                        char paramCount = m_Content.GetAt(i);
                        i++;
                        if (code == 0x43 && paramCount == 4 && i + paramCount <= m_Content.Size)
                        {
                            // Start of colour.
                            if (pCurrItem.Text.Size != 0)
                            {
                                pCurrItem = pCurrItem.NewItem(); pCurrLine.Items.Append(pCurrItem);
                            }
                            pCurrItem.Colour = new MHRgba(m_Content.GetAt(i), m_Content.GetAt(i + 1),
                                                          m_Content.GetAt(i + 2), 255 - m_Content.GetAt(i + 3));
                            // Push this colour onto the colour stack.
                            m_ColourStack.Push(pCurrItem.Colour);
                        }
                        else
                        {
                            Logging.Log(Logging.MHLogWarning, "Unknown text escape code " + code);
                        }
                        i += paramCount;                   // Skip the parameters
                    }
                    else if (code >= 0x60 && code <= 0x7e) // End code.
                    {
                        i++;
                        if (code == 0x63)
                        {
                            if (m_ColourStack.Count > 1)
                            {
                                m_ColourStack.Pop();
                                // Start a new item since we're using a new colour.
                                if (pCurrItem.Text.Size != 0)
                                {
                                    pCurrItem = pCurrItem.NewItem();
                                    pCurrLine.Items.Append(pCurrItem);
                                }
                                // Set the subsequent text in the colour we're using now.
                                pCurrItem.Colour = m_ColourStack.Peek();
                            }
                        }
                    }
                }

                else if (ch <= 0x1f)
                {
                    // Certain characters including LF and the marker codes between 0x1c and 0x1f are
                    // explicitly intended to be ignored.  Include all the other codes.
                }

                else   // Add to the current text.
                {
                    int nStart = i - 1;
                    while (i < m_Content.Size && m_Content.GetAt(i) >= 0x20)
                    {
                        i++;
                    }
                    pCurrItem.Text.Append(new MHOctetString(m_Content, nStart, i - nStart));
                }
            }


            // Set up the initial attributes.
            int style, size, lineSpace, letterSpace;

            InterpretAttributes(m_fontAttrs, out style, out size, out lineSpace, out letterSpace);
            // Create a font with this information.
            m_pDisplay.SetFont(size, (style & 2) != 0, (style & 1) != 0);

            // Calculate the layout of each section.
            for (i = 0; i < theText.Size; i++)
            {
                MHTextLine pLine = theText.GetAt(i);
                pLine.LineWidth = 0;
                for (int j = 0; j < pLine.Items.Size; j++)
                {
                    MHTextItem pItem = pLine.Items.GetAt(j);
                    // Set any tabs.
                    for (int k = 0; k < pItem.TabCount; k++)
                    {
                        pLine.LineWidth += TABSTOP - pLine.LineWidth % TABSTOP;
                    }

                    if (pItem.UnicodeLength == 0)
                    { // Convert UTF-8 to Unicode.
                        int s = pItem.Text.Size;
                        pItem.Unicode       = pItem.Text.ToString();
                        pItem.UnicodeLength = pItem.Unicode.Length;
                    }
                    // Fit the text onto the line.
                    int nFullText = pItem.UnicodeLength;
                    // Get the box size and update pItem.m_nUnicode to the number that will fit.
                    Rectangle rect = m_pDisplay.GetBounds(pItem.Unicode, ref nFullText, m_nBoxWidth - pLine.LineWidth);
                    if (nFullText == pItem.UnicodeLength || !m_fTextWrap)
                    {
                        // All the characters fit or we're not wrapping.
                        pItem.Width      = rect.Width;
                        pLine.LineWidth += rect.Width;
                    }

                    /*                   else if (m_fTextWrap)
                     *                 { // No, we have to word-wrap.
                     *                     int nTruncated = pItem.UnicodeLength; // Just in case.
                     *                     // Now remove characters until we find a word-break character.
                     *                     while (pItem.UnicodeLength > 0 && pItem.Unicode[pItem.UnicodeLength] != ' ') pItem.UnicodeLength--;
                     *                     // If there are now word-break characters we truncate the text.
                     *                     if (pItem.UnicodeLength == 0) pItem.UnicodeLength = nTruncated;
                     *                     // Special case to avoid infinite loop if the box is very narrow.
                     *                     if (pItem.UnicodeLength == 0) pItem.UnicodeLength = 1;
                     *
                     *                     // We need to move the text we've cut off this line into a new line.
                     *                     int nNewWidth = nFullText - pItem.UnicodeLength;
                     *                     int nNewStart = pItem.UnicodeLength;
                     *                     // Remove any spaces at the start of the new section.
                     *                     while (nNewWidth != 0 && pItem.Unicode[nNewStart] == ' ') { nNewStart++; nNewWidth--; }
                     *                     if (nNewWidth != 0) {
                     *                         // Create a new line from the extra text.
                     *                         MHTextLine pNewLine = new MHTextLine();
                     *                         theText.InsertAt(pNewLine, i+1);
                     *                         // The first item on the new line is the rest of the text.
                     *                         MHTextItem pNewItem = pItem.NewItem();
                     *                         pNewLine.Items.Append(pNewItem);
                     *                         pNewItem.Unicode = pItem.Unicode.Substring(nNewStart, nNewWidth);
                     *                         pNewItem.UnicodeLength = nNewWidth;
                     *                     }
                     *                     // Remove any spaces at the end of the old section.  If we don't do that and
                     *                     // we are centering or right aligning the text we'll get it wrong.
                     *                     while (pItem.UnicodeLength > 1 && pItem.Unicode[pItem.UnicodeLength - 1] == ' ') pItem.UnicodeLength--;
                     *                     int uniLength = pItem.UnicodeLength;
                     *                     rect = m_pDisplay.GetBounds(pItem.Unicode, ref uniLength, 0);
                     *                     pItem.Width = rect.Width;
                     *                     pLine.LineWidth += rect.Width;
                     *                 }
                     */}
            }

            // Now output the text.
            int yOffset = 0;
            // If there isn't space for all the lines we should drop extra lines.
            int nNumLines = theText.Size;

            do
            {
                if (m_VertJ == End)
                {
                    yOffset = m_nBoxHeight - nNumLines * lineSpace;
                }
                else if (m_VertJ == Centre)
                {
                    yOffset = (m_nBoxHeight - nNumLines * lineSpace) / 2;
                }
                if (yOffset < 0)
                {
                    nNumLines--;
                }
            } while (yOffset < 0);

            for (i = 0; i < nNumLines; i++)
            {
                MHTextLine pLine   = theText.GetAt(i);
                int        xOffset = 0;
                if (m_HorizJ == End)
                {
                    xOffset = m_nBoxWidth - pLine.LineWidth;
                }
                else if (m_HorizJ == Centre)
                {
                    xOffset = (m_nBoxWidth - pLine.LineWidth) / 2;
                }
                //ASSERT(xOffset >= 0);

                for (int j = 0; j < pLine.Items.Size; j++)
                {
                    MHTextItem pItem = pLine.Items.GetAt(j);
                    // Tab across if necessary.
                    for (int k = 0; k < pItem.TabCount; k++)
                    {
                        xOffset += TABSTOP - xOffset % TABSTOP;
                    }
                    if (pItem.Unicode.Length != 0)           // We may have blank lines.
                    {
                        m_pDisplay.AddText(xOffset, yOffset, // Jas removed this cos it doesn't make sense yOffset + lineSpace
                                           pItem.Unicode.Substring(0, pItem.UnicodeLength), pItem.Colour);
                    }
                    xOffset += pItem.Width;
                }
                yOffset += lineSpace;
                if (yOffset + lineSpace > m_nBoxHeight)
                {
                    break;
                }
            }
        }